Re: [Haskell-cafe] Monad.Reader 8: Haskell, the new C++

2007-09-14 Thread Adrian Neumann
-BEGIN PGP SIGNED MESSAGE-
Hash: RIPEMD160

I heard only rumors, but isn't Lisp supposed to be just that? A
programmable programming language?

Peter Verswyvelen schrieb:
 This is all very cool stuff, but sometimes I wander if it isn't possible
 to drop the special languages for fiddling with types, and introduce
 just a single language which has no types, only raw data from which you
 can built your own types (as in the old days when we used macro
 assemblers ;-), but the language has two special keywords: static and
 dynamic, where code annotated with static runs in the compiler domain,
 and code annotated with dynamic runs in application domain. Of course,
 I don't know much about this, so this idea might be totally insane ;-)
 Probably this is impossible because of the halting problem or something...
 
 Pete
 
 Don Stewart wrote:
 Better here means better -- a functional language on the type 
 system,
 to type a functional language on the value level.

 -- Don
   
 For a taste, see Instant Insanity transliterated in this functional 
 language:

 http://hpaste.org/2689

 NB: it took me 5 minutes, and that was my first piece of coding ever 
 with Type families
 

 Wow. Great work!
 The new age of type hackery has dawned.

 -- Don
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


   
 
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFG6ikc11V8mqIQMRsRA+PzAKCN0bC6lv8p9WEwJkJrcczktIdKGACfUdkt
0QBGlmgwfYrKS6lKEwQihkc=
=31jo
-END PGP SIGNATURE-
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] wxhaskell package for ubuntu feisty, amd64

2007-09-14 Thread Iván Pérez Domínguez
I'm trying to install wxhaskell in ubuntu feisty,  with ghc-6.6.

After several days of trial and error and a few hours trying to
change all types in my program to gtk2hs types, I'm tired.

Does anyone have a .deb for wxhaskell that works with ghc-6.6?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


RE: [Haskell-cafe] wxhaskell package for ubuntu feisty, amd64

2007-09-14 Thread José Miguel Vilaça
Hi Iván,

Try this:

* install GHC and darcs:
sudo apt-get install ghc6
sudo apt-get install darcs
* install WxWidgets 2.6
sudo apt-get install libwxgtk2.6-dev
sudo apt-get install freeglut3-dev
sudo apt-get install g++
* install wxHaskell
darcs get http://darcs.haskell.org/wxhaskell
cd wxhaskell
chmod u+x configure
./configure --with-opengl
make
sudo make install
make wx
sudo make wx-install
cd ..
* test wxhaskell with ghc
ghci -package wx

It's working in my laptop!

Best
Miguel

P.S. This link could be helpful:
http://wiki.loria.fr/wiki/GenI/Getting_GenI/Instructions_for_Ubuntu_Linux 

-Mensagem original-
De: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Em nome de Iván Pérez Domínguez
Enviada: sexta-feira, 14 de Setembro de 2007 11:36
Para: haskell-cafe@haskell.org
Assunto: [Haskell-cafe] wxhaskell package for ubuntu feisty, amd64

I'm trying to install wxhaskell in ubuntu feisty,  with ghc-6.6.

After several days of trial and error and a few hours trying to
change all types in my program to gtk2hs types, I'm tired.

Does anyone have a .deb for wxhaskell that works with ghc-6.6?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Clarification Please

2007-09-14 Thread Andrew Wagner
You may also find this function helpful. I'll let you work out why/how:
uncurry :: (a - b - c) - (a, b) - c
uncurry f p = f (fst p) (snd p)

On 9/13/07, Krzysztof Kościuszkiewicz [EMAIL PROTECTED] wrote:
 On Fri, Sep 14, 2007 at 03:45:02AM +0100, PR Stanley wrote:

  5. Using merge, define a recursive function
  msort :: (Ord a) = [a] - [a]
  that implements merge sort, in which the empty
  list and singleton lists are already sorted, and
  any other list is sorted by merging together the
  two lists that result from sorting the two halves of the list separately. :
  Hint: first define a function
  ¬halve :: [a] - [([a], [a])]
  ¬that splits a list into two halves whose length differs by at most one.

 Split the input list using halve, sort both halves (as merge requires lists to
 be sorted) and merge them into output list...

 Regards,
 --
 Krzysztof Kościuszkiewicz
 Skype: dr.vee,  Gadu: 111851,  Jabber: [EMAIL PROTECTED]
 Mobile IRL: +353851383329,  Mobile PL: +48783303040
 Simplicity is the ultimate sophistication -- Leonardo da Vinci
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: interaction between OS processes

2007-09-14 Thread Bryan O'Sullivan

Aaron Denney wrote:


If you want expect like functionality, i.e. working for arbitrary
client programs, you'll need to use pseudottys, as expect, script,
screen, xterm, etc. do.


I packaged up a patch for System.Posix to add this a month or three ago, 
but forgot to follow through on it.  Thanks for the (albeit indirect) 
reminder :-)


b
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Monad.Reader 8: Haskell, the new C++

2007-09-14 Thread Stefan Monnier
 PS: And, no, you won't be able to set breakpoints in type-level
 programs...

Yet.


Stefan

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Monad.Reader 8: Haskell, the new C++

2007-09-14 Thread Peter Verswyvelen
I'm not sure, I don't know LISP in detail, but as far as I know, LISP is 
a fully dynamic language.


I actually meant a static language where you build your own strong types 
using the language itself. On the micro level, the language only knows 
abouts bits and bytes without semantics, just like assembler, no types 
at all. But the language allows you to build whatever type or 
semantics you want from scratch, by providing a keyword that forces 
certain part of the program to be evaluated at compile time. A bit like 
macros, but written in the same language. Although not exactly the same, 
the Digital Mars D language has a static if (p) { q } statement, where 
p must evaluate to a constant expression at compile time, otherwise the 
compiler gives an error/warning (I'm not sure, haven't tried it yet). 
You can do that in C++ (using templates) and Haskell (using types) but 
these are actually mini-sub-languages. Probably giving control to the 
programmer of how type-checking should be coded bypasses the advantages 
of strong typing, so this is most likely a dumb idea...


Anyway, I should not mention these ideas, I'm just a programmer, not a 
computer scientist ;-)


Peter

Adrian Neumann wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: RIPEMD160

I heard only rumors, but isn't Lisp supposed to be just that? A
programmable programming language?

Peter Verswyvelen schrieb:
  

This is all very cool stuff, but sometimes I wander if it isn't possible
to drop the special languages for fiddling with types, and introduce
just a single language which has no types, only raw data from which you
can built your own types (as in the old days when we used macro
assemblers ;-), but the language has two special keywords: static and
dynamic, where code annotated with static runs in the compiler domain,
and code annotated with dynamic runs in application domain. Of course,
I don't know much about this, so this idea might be totally insane ;-)
Probably this is impossible because of the halting problem or something...

Pete

Don Stewart wrote:

Better here means better -- a functional language on the type 
system,

to type a functional language on the value level.

-- Don
  
  
For a taste, see Instant Insanity transliterated in this functional 
language:


http://hpaste.org/2689

NB: it took me 5 minutes, and that was my first piece of coding ever 
with Type families



Wow. Great work!
The new age of type hackery has dawned.

-- Don
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


  
  

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe



-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFG6ikc11V8mqIQMRsRA+PzAKCN0bC6lv8p9WEwJkJrcczktIdKGACfUdkt
0QBGlmgwfYrKS6lKEwQihkc=
=31jo
-END PGP SIGNATURE-
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


  


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Monad.Reader 8: Haskell, the new C++

2007-09-14 Thread Toby Allsopp
Peter Verswyvelen writes:

 I'm not sure, I don't know LISP in detail, but as far as I know, LISP
 is a fully dynamic language.

 I actually meant a static language where you build your own strong
 types using the language itself.
[...]

You might be interested in the Qi language[1].

Qi is implemented on top of Common Lisp using macros (and probably
other things) and provides (optional) static type checking as well as
various functional programming features (pattern matching, partial
function application, etc.)

The implementation, including all of the type checking, is in Common
Lisp and runs during compilation (well, technically at macro-expansion
time.)  A Qi program is just a Common Lisp program that can choose to
use the features provided by these macros.

Regards,
Toby.

Footnotes: 
[1] http://www.lambdassociates.org/aboutqi.htm

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Sequencing Operations in a Monad

2007-09-14 Thread SevenThunders

I have a matrix library written in C and interfaced into Haskell with a lot
of additional Haskell
support.  The C library of course has a lot of side effects and actually
ties into the BLAS libraries, thus at the present time, most of the
interesting calls are done in the IO monad.  I have no intention of
rewriting what I've done so far or using someone elses Matrix library. 
(Mine is tuned somewhat for my application).

I attempted to extend my Haskell matrix interface using type classes (real
and complex matrices) and have run into a conceptual problem.  I would like
to be able to use operator notation for matrix arithmetic.
e.g.
R = Q * (A + B)

Unfortunately if I wrap my  matrix references in the IO monad, then at best
computations like 
S = A + B are themselves IO computations and thus whenever they are
'invoked' the computation ends up getting performed repeatedly contrary to
my intentions.  For example I might have some code like this,

let S = A += B in
   do
   (r,c) -  size S
   k  - matindex S
.

code of this nature results in S being applied twice and if  the operator += 
has side effects, those side effects will be applied twice.  Even if there
are no side effects the computation will unnecessarily be applied twice. 
What I need is a way to force a single execution of the IO action without
losing the syntax sugar. 

 If you arrange the types to try to do all the operations inside the IO
monad you can't chain together more than 1 binary operation.  eg.

do
   S - A + B
   Z - Q * S

vs

do 
   S -  Q * (A + B)

Are there any suggestions for this dilemma?  Am I using the wrong monad for
this task?
-- 
View this message in context: 
http://www.nabble.com/Sequencing-Operations-in-a-Monad-tf4446047.html#a12685983
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Memory leak or wrong use of Array ?

2007-09-14 Thread L.Guo
Hi Stuart.

Thanks for your advice about thunk, though I do not understand *thunk*
very well. Is there any other discriptions about thunk ?

I have tried the *seq* operation. When input is 10,000,000, the memory
still leak, and there is still a stack overflow.

I changed some mapM_ to sequence . map f, and tried to save some division.

The key functions now looks like this:

  proportions n = unsafePerformIO $ do
  arr - newArray (2,n) (False,1/1) :: Fractional t = IO (IOArray Int 
(Bool,t))
  sequence_ $ map (sieve arr n) [2..n]
  factors - getElems arr
  return . map (\(n,(b,f)) - (f,n)) $ zip [2..n] factors
where
  sieve arr ubound p = do
  (b,o) - readArray arr p
  if b then return () else
sequence_ . map (update arr (toRational p)) . takeWhile (=ubound) 
$ iterate (+p) p
  update arr p i = do
  (_,o) - readArray arr i
  --writeArray arr i (True,o*(p-1)/p)
  let val = o * p / (p-1)
  val `seq` return () -- force the thunk
  writeArray arr i (True, val)
  solutionOf = snd . minimum
 . filter (\(f,n) - isPerm (floor $ toRational n/f) n) . 
proportions

--   
L.Guo
2007-09-15


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Memory leak or wrong use of Array ?

2007-09-14 Thread Brandon S. Allbery KF8NH


On Sep 14, 2007, at 21:35 , L.Guo wrote:


Thanks for your advice about thunk, though I do not understand *thunk*
very well. Is there any other discriptions about thunk ?


A thunk is, in general, a piece of code which represents a  
suspended or delayed action.  In Haskell, it represents a lazy  
computation:  Haskell will only evaluate the code if the value is  
actually needed, and even then only just enough to satisfy the  
immediate need (thus, the result of evaluating a thunk may be a  
value, or another thunk).


--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED]
system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED]
electrical and computer engineering, carnegie mellon universityKF8NH


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Sequencing Operations in a Monad

2007-09-14 Thread Ryan Ingram
As long as the FFI calls don't make destructive updates to existing
matrices, you can do what you want.

For example, assuming you have:

-- adds the second matrix to the first  overwrites the first
matrixAddIO :: MatrixIO - MatrixIO - IO ()

-- creates a new copy of a matrix
matrixCopyIO :: MatrixIO - IO MatrixIO

Then you can define safe operators like this:

module Matrix (
   Matrix,
   matrixCreate,
   matrixAdd
) where
import System.IO.Unsafe (unsafePerformIO)

newtype Matrix = Matrix { liftMatrix :: MatrixIO }

matrixCreate :: MatrixIO - IO Matrix
matrixCreate m = do
   mNew - matrixCopyIO m
   return (Matrix mNew)

matrixAdd :: Matrix - Matrix - Matrix
matrixAdd (Matrix m1) (Matrix m2) = unsafePerformIO $ do
   mDest - matrixCopyIO m1
   matrixAddIO mDest m2
   return (Matrix mDest)

What is important is that every use of unsafePerformIO comes with a
proof at some level that the computation really is functional; that
is, that the result depends only on the inputs and not on the order of
operations.  An informal sketch of this proof for this bit of code:

1) Matrices are only injected into the system via matrixCreate, which
is an ordered operation in the IO Monad; the Matrix constructor is
not exported.

2) matrixCreate copies its source data.  So changes to source MatrixIO
objects can't affect any Matrix.

3) matrixAddIO only modifies its first argument, not the second.  We
only call it with a brand-new matrix object, so it's safe to modify
there.

You should be able to expand this to the point that you can implement
Num operations.  But be warned that efficiency may suffer; lots of
intermediate matrices get created, used once, and then discarded.
It's possible that you can use GHC rules to rewrite  fuse operations
which would help; I'd expect a serious matrix library to do so.  See
http://www.haskell.org/ghc/docs/latest/html/users_guide/rewrite-rules.html

 -- ryan
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Sequencing Operations in a Monad

2007-09-14 Thread SevenThunders



Ryan Ingram wrote:
 
 As long as the FFI calls don't make destructive updates to existing
 matrices, you can do what you want.
 
 For example, assuming you have:
 
 -- adds the second matrix to the first  overwrites the first
 matrixAddIO :: MatrixIO - MatrixIO - IO ()
 
 -- creates a new copy of a matrix
 matrixCopyIO :: MatrixIO - IO MatrixIO
 ...
 
 
Well as you point out there is an efficiency issue if we need to copy
matrices all of the time in order to insure 'referential transparency'.  
Moreover I manage my matrices on a stack  in C, since it makes it easy to
handle memory allocation and deallocation.  The stack configuration tends to
be highly fluid so there are always side effects going on.  Right now my
Matrix type wraps the index from the bottom of the Matrix stack into the IO
monad.   

 I was just wondering if there was any obvious way to force an IO action to
execute only once, since now each reference to the action IO causes it to
execute again.
-- 
View this message in context: 
http://www.nabble.com/Sequencing-Operations-in-a-Monad-tf4446047.html#a12686766
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Sequencing Operations in a Monad

2007-09-14 Thread Ronald Guida

SevenThunders wrote:

I have a matrix library written in C and interfaced into Haskell
with a lot of additional Haskell support.


[snip]


Unfortunately if I wrap my matrix references in the IO monad, then
at best computations like S = A + B are themselves IO computations
and thus whenever they are 'invoked' the computation ends up getting
performed repeatedly contrary to my intentions.


Here's some thoughts:

First, the IO monad already does sequencing, and it already has the
ability to execute an action once only.

Let's look at an example:


test1 = do
  putStr What is your name? 
  n - getLine
  putStrLn $ Hello,  ++ n ++ !
  return n



getName :: IO String - IO String
getName nameAction = do
  n - nameAction-- execute the action
  return n



getNameLength :: IO String - IO Int
getNameLength nameAction = do
  n - nameAction-- execute the action
  return $ length n



test2 = do
  let nameAction = test1 in do
n - getName nameAction
putStrLn $ Name =  ++ n
len - getNameLength nameAction
putStrLn $ Length =  ++ show len



test3 = do
  n - test1
  putStrLn $ Name =  ++ n
  putStrLn $ Length =  ++ show (length n)



test4 = do
  let nameAction = test1 in do
n - nameAction
n' - getName (return n)
putStrLn $ Name =  ++ n'
len - getNameLength (return n)
putStrLn $ Length =  ++ show len


GHCi test1
What is your name? Ron
Hello, Ron!
Ron

GHCi test2
What is your name? Alice
Hello, Alice!
Name = Alice
What is your name? Bob
Hello, Bob!
Length = 3

GHCi test3
What is your name? Ron
Hello, Ron!
Name = Ron
Length = 3

GHCi test4
What is your name? Ron
Hello, Ron!
Name = Ron
Length = 3

Notice that in test2, I am asked for my name twice.  This behavior is
expected because the functions GetName and getNameLength each
accept an action and execute it to get a name.

In test3, I am only asked for my name once.  I only want to execute
the action once, so I have to code it that way.

Before I explain test4, let's look at your example code:


let S = A += B in
  do
  (r,c) -  size S
  k  - matindex S


If S is being executed twice, then clearly S is an action.  Perhaps
the type of S is IO MatrixIO ?  If that's true, then presumably the
functions size and matindex have signatures:

size :: IO MatrixIO - IO (Int, Int)
matindex :: IO MatrixIO - IO Int

Each function takes an IO action as its first argument, executes that
action, and then computes a result.

My two functions getName and getNameLength are similar to size
and matindex: each function takes an IO action, executes the action,
and computes a result.

Now, look at test4.  That's how I can work around the behaviour of
getName and getNameLength while ensuring that I am only asked for
my name one time.  This works because return creates an IO action
that does nothing and simply returns its argument.

I could translate your example to the following:


let S = A += B in
  do
  s - S
  (r,c) -  size (return s)
  k  - matindex (return s)


This should only perform action S one time.

In fact, functions like getNameLength are poorly designed functions
because they fail on Separation of concerns.  The getNameLength
function is doing two different things: (1) it executes an IO action
to get a name, and then (2) it computes and returns the name's length.
In test4, I am bypassing the execution of an IO action by passing the
non-action return n to the getNameLength function.

A simple design rule would be: A function should not take an IO action
as an input if that action is to executed exactly once and only once.

Let's move on to chained binary operations.


If you arrange the types to try to do all the operations inside the
IO monad you can't chain together more than 1 binary operation.


Using your example, suppose I want to compute S := Q * (A + B), but I
don't have a function that computes A + B.  Instead, what I have is a
function that computes A += B by modifying A in place.

If I want to compute S, and I don't care about preserving A, then I
would perform the following steps:
A += B;  S := Q * A

If I do want to preserve A, then I need to copy it first.
A' := copy A; A' += B; S := Q * A'

No matter what, I cannot escape the need to explicitly sequence the
operations.

In C++, I could play some very sophisticated games with templates and
operator overloading to coax the C++ compiler to accept an expression
with chained operations like S = Q * (A + B) and do the right
thing.  In Haskell, I'm pretty sure the corresponding techniques
involve using arrows.

If you don't want that level of sophistication, then you are best off
coding what you mean, as in:

do
-- compute S := Q * (A + B)
C - A + B
S - Q * C

Now, there's just one more thing [emphasis added].


Moreover I manage my matrices on a stack in C, since it makes it
easy to handle memory allocation and deallocation.  *The stack*
*configuration tends to be highly fluid so there are always side*
*effects going on.*  Right now my 

Re: [Haskell-cafe] haskell on llvm?

2007-09-14 Thread Ryan Dickie
I could see it as a useful abstraction instead of directly generating
assembly. To me the idea behind llvm seems nice and clean and academic to a
certain degree. It can see it as something to look out for in the future.

On 9/13/07, brad clawsie [EMAIL PROTECTED] wrote:

 has anyone ever considered using llvm as a infrastructure for haskell
 compilation? it wold seem people are looking at building frontends for
 scheme, ocaml, etc. i don't know if an alternate backend is
 appropriate, but it would seem to be an interesting way to aggregate
 the best thinking for various optimizations over a more diverse group
 of developers.
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe