Re: [Haskell-cafe] The Monad.Reader (11) - Call for Copy

2008-05-08 Thread Wouter Swierstra

Hi Donnie,

Any chance of those issues being moved over still?  I'd prefer to  
read the older issues in pdf format, like the new issues.


I have gotten permission from (almost) all the authors to move the  
content to the new wiki. I've started reformatting everything to the  
MediaWiki format - for example:


http://www.haskell.org/haskellwiki/The_Monad.Reader/Issue2

Unfortunately, progress is pretty slow. The automated tools to convert  
between MoinMoin and MediaWiki are pretty crummy; reformatting by hand  
is a fair amount of boring work; I'm writing up my thesis at the  
moment, so it's not very high on my list of things to do, I'm afraid.


If you, or anyone else, would like to help out it would be much  
appreciated! It's just too much work for me to do by myself.


All the best,

  Wouter

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


Re: [Haskell-cafe] I am new to haskell

2008-05-08 Thread Giorgio Valoti


On 08/mag/08, at 08:59, Benjamin L. Russell wrote:
One hint that is not (at least to my knowledge) listed on  
haskell.org is that, according to at least one user (see "The  
Programmers’ Stone » Blog Archive » A First Haskell Experience" at  
http://the-programmers-stone.com/2008/03/04/a-first-haskell- 
experience/), the online tutorials can "confuse more than they  
illuminate."


Personally, I would recommend starting with one of the available  
books (see "Books - HaskellWiki" at http://haskell.org/haskellwiki/ 
Books), instead.  In particular, I would recommend one of the  
following titles:

[…]


What’s your opinion on Programming in Haskell by Graham Hutton. It is  
the first book about Haskell that I’ve read and wondering what could  
be the next one. Should I wait for Real world Haskell or do you think  
that the books you listed offer something new/different/more advanced  
than Programming in Haskell?



Thank you in advance
--
Giorgio Valoti




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


[Haskell-cafe] "resource exhausted"

2008-05-08 Thread Galchin, Vasili
Hello,

I am running some monadic code that I have written. I double checked my
code and it seems to be ok (no guarantee though). I am getting a "resource
exhausted (Message too long)". I just did a google on "resource exhausted"
and saw a few posts on the number of open files which is obviously not my
case. Any ideas?

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


Re: [Haskell-cafe] Interesting critique of OCaml

2008-05-08 Thread Michael Vanier

Actually, it's (+) for ints and (+.) for floats.  Which kind of proves your 
point.

Mike

Tim Docker wrote:

| An interesting critique of OCaml.
| 
| http://enfranchisedmind.com/blog/2008/05/07/why-ocaml-sucks/


Interesting to me is that my pet ocaml peeve is not there: namely the
lack of convenient operator overloading. Admittedly I only used ocaml
for 6 months, but I never adapted to needing to write (+) for ints, and
(.+) for floats.


From the F# documentation it would appear that F# does have overloaded

numerical operators, at least. I'm not sure how these fit into its type
system however. (Their type is documented as "overloaded").

Tim 


___
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] Interesting critique of OCaml

2008-05-08 Thread Tim Docker
| An interesting critique of OCaml.
| 
| http://enfranchisedmind.com/blog/2008/05/07/why-ocaml-sucks/

Interesting to me is that my pet ocaml peeve is not there: namely the
lack of convenient operator overloading. Admittedly I only used ocaml
for 6 months, but I never adapted to needing to write (+) for ints, and
(.+) for floats.

>From the F# documentation it would appear that F# does have overloaded
numerical operators, at least. I'm not sure how these fit into its type
system however. (Their type is documented as "overloaded").

Tim 

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


Re[2]: [Haskell-cafe] Newbie Question: Using Haskell Functions in a C Program

2008-05-08 Thread Bulat Ziganshin
Hello Philip,

Friday, May 9, 2008, 3:09:33 AM, you wrote:

> Thanks for all the answers. I'm testing this right now and simples cases
> work as expected. However from what I've read it seems it'll get ugly 
> once I try to pass a C array to a Haskell function.

http://haskell.org/haskellwiki/Modern_array_libraries

read about foreign arrays

-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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


Re: [Haskell-cafe] Stack vs Heap allocation

2008-05-08 Thread Albert Y. C. Lai

Edsko de Vries wrote:

sum :: Tree -> Int
sum t = sum' [t] 0
  where
sum' [] acc = acc
sum' (Leaf i : ts) acc = sum' ts $! (i + acc)
sum' (Node l r : ts) acc = sum' (l : r : ts) acc


Because of $!, you should compare the Leaf case to foldl', not foldl.

The Node case can be said to mimic a stack using heap resource.

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


Re: [Haskell-cafe] Newbie Question: Using Haskell Functions in a C Program

2008-05-08 Thread Don Stewart
mail:
> Thanks for all the answers. I'm testing this right now and simples 
> cases work as expected. However from what I've read it seems it'll 
> get ugly once I try to pass a C array to a Haskell function.

Right, passing arrays back and forth is going to get tiring.
  
> Well, maybe arrays in C have been ugly before trying to pass them to 
> Haskell functions ;)
> 
> To elaborate a bit about the C program, it's a small game using 
> OpenGL for output and mouse and keyboard for input.
> I just don't know how to do that in Haskell - my knowledge is quite 
> basic in nature ;)

Oh, then you'll want to use the Haskell OpenGL bindings.

http://hackage.haskell.org/cgi-bin/hackage-scripts/package/OpenGL

There's a few OpenGL-based games in Haskell, here:

http://haskell.org/haskellwiki/Applications_and_libraries/Games

and a section of blog articles on using the OpenGL bindings:

http://haskell.org/haskellwiki/Blog_articles/Graphics#OpenGL

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


Re: [Haskell-cafe] Induction (help!)

2008-05-08 Thread Ryan Ingram
On 5/8/08, Daniel Fischer <[EMAIL PROTECTED]> wrote:
> No. In the induction step, we prove that
> IF p(j) holds, THEN p(j+1) holds, too.
> p(j) is the assumption, and we prove that *given that assumption*, p(j+1)
> follows.
> Then we have proved
> (*) p(j) implies p(j+1), for all j.

To formalize this, you can work in a system of logic with the following rules:

Variable introduction:
   x is not free in L,
   L |- t is a type
   proves
   L, x :: t |- x :: t --- this is a proof of "x has type t"

Forall introduction (removing the above assumption)
   L, x :: t |- p
   proves
   L |- forall x :: t. p

Assumption of a proposition:
   L, p |- p--- no pre-requisites

Impication introduction ("Deduction"; if P then Q)
   L, p |- q
   proves
   L |- p => q

The part to the left of the |- is an "environment"; it represents
assumptions you have made up to this point.   The part to the right is
a statement which is "true" in that environment; the L just represents
"any environment".

For example, in the first rule, we say that if we know that t is a
type, and we haven't assumed anything about x yet, we can assume that
x is a member of that type.  Then in the second rule, if we've proved
some proposition "p" once we've assumed that x is something of type t,
we can say that p holds for -all- x of type t; we didn't assume
anything about that x besides its type.

Induction corresponds to adding the following rule to the logic:

L |- p(0)
L |- forall x :: Nat, p(x) => p(x+1)
proves
L |- forall x :: Nat, p(x)

A "true" statement is one that holds with no environment:
|- p

Now, if you are proving something by induction, you had to prove that
second line; and the only way to do so is by making some assumptions.
A skeleton of a proof:

axiom
|- Nat is a type

variable introduction
x :: Nat |- x :: Nat

proposition introduction
x :: Nat, p(x) |- p(x)

... some proof using p(x) here ...
x :: Nat, p(x) |- p(x+1)

deduction
x :: Nat |- p(x) => p(x+1)

forall introduction
|- forall x :: Nat, p(x) => p(x+1)

... some proof of p(0) here ...
|- p(0)

induction
|- forall x :: Nat, p(x)

Every proof by induction looks basically like this; you just need to
fill in the "... some proof here..." parts.

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


Re: [Haskell-cafe] Newbie Question: Using Haskell Functions in a C Program

2008-05-08 Thread Philip Müller
Thanks for all the answers. I'm testing this right now and simples cases 
work as expected. However from what I've read it seems it'll get ugly 
once I try to pass a C array to a Haskell function.


Well, maybe arrays in C have been ugly before trying to pass them to 
Haskell functions ;)


To elaborate a bit about the C program, it's a small game using OpenGL 
for output and mouse and keyboard for input.
I just don't know how to do that in Haskell - my knowledge is quite 
basic in nature ;)


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


Re: [Haskell-cafe] Stack vs Heap allocation

2008-05-08 Thread Derek Elkins
On Thu, 2008-05-08 at 23:29 +0100, Edsko de Vries wrote:
> Hi,
> 
> How can I know whether something will be stack or heap allocated? For
> example, in the standard example of why 
> 
> foldl (+) 0
> 
> will fail to evaluate a long list of integers due to a stack overflow,
> but foldl' won't, it is pointed out that foldl starts building up
> unevaluated thunks. So, apparently, these thunks are allocated on the
> stack rather than on the heap with a pointer to the thunk on the stack.
> (I understand that foldl' is asymptotically better than foldl
> space-wise; that is irrelevant to my question.)
> 
> On the other hand, in this version that sums all the values in a tree
> 
> data Tree = Leaf Int | Node Tree Tree
> 
> sum :: Tree -> Int
> sum t = sum' [t] 0
>   where
> sum' [] acc = acc
> sum' (Leaf i : ts) acc = sum' ts $! (i + acc)
> sum' (Node l r : ts) acc = sum' (l : r : ts) acc
> 
> we are building up a (potentially) large lists of trees yet to be
> processed, but never run out of stack space. Apparently, the list is
> built up on the heap rather than on the stack. 
>  
> What is the fundamental difference between these two examples? Why is
> the list of trees yet to be processed allocated on the heap (with a
> pointer on the stack, presumably) but the unevaluated thunks in the
> foldl example allocated on the stack?


No, the thunks are (usually) stored on the heap.  You don't get the
stack overflow until you actually force the computation at which point
you have an expression like:
(...(((1+2)+3)+4) ... + 1000)
which requires stack in proportion to the number of nested parentheses
(effectively)

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


Re: [Haskell-cafe] Newbie Question: Using Haskell Functions in a C Program

2008-05-08 Thread Don Stewart
mail:
> Is there a way to write some of the functions in Haskell and then use 
> them in my C code via some kind of interface?

Using C just for IO is a bit weird -- perhaps you could illustrate
the kind of IO you're doing?  Learning how to do IO in Haskell is 
a much safer solution that linking the Haskell runtime into your
C program.

That said, this is done by using 'foreign export' declarations
in your Haskell code, then linking the compiled Haskell objects 
into your C code, as follows:


We define the fibonacci function in Haskell:


{-# LANGUAGE ForeignFunctionInterface #-}

module Safe where

import Foreign.C.Types

fibonacci :: Int -> Int
fibonacci n = fibs !! n
where fibs = 0 : 1 : zipWith (+) fibs (tail fibs)

fibonacci_hs :: CInt -> CInt
fibonacci_hs = fromIntegral . fibonacci . fromIntegral

foreign export ccall fibonacci_hs :: CInt -> CInt


And call it from C:

#include "A_stub.h"
#include 

int main(int argc, char *argv[]) {
   int i;
   hs_init(&argc, &argv);

   i = fibonacci_hs(42);
   printf("Fibonacci: %d\n", i);

   hs_exit();
   return 0;
}

Now, first compile the Haskell file:

$ ghc -c -O A.hs

Which creates some *.c and *.h headers, which you import into
your C program. Now compile your C code with ghc (!), passing
the Haskell objects on the command line:

$ ghc -optc-O test.c A.o A_stub.o -o test

How run your C code:

$ ./test 
Fibonacci: 267914296

And that's it.

-- Don

P.S. Its easier to learn how to do IO in Haskell :)
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Newbie Question: Using Haskell Functions in a C Program

2008-05-08 Thread Bulat Ziganshin
Hello Philip,

Friday, May 9, 2008, 2:17:41 AM, you wrote:

> Is there a way to write some of the functions in Haskell and then use
> them in my C code via some kind of interface?

http://haskell.org/haskellwiki/IO_inside#Interfacing_with_foreign_evil_.28under_development.29

and then entries 1,6,7 in 
http://haskell.org/haskellwiki/IO_inside#Further_reading


-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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


[Haskell-cafe] Stack vs Heap allocation

2008-05-08 Thread Edsko de Vries
Hi,

How can I know whether something will be stack or heap allocated? For
example, in the standard example of why 

foldl (+) 0

will fail to evaluate a long list of integers due to a stack overflow,
but foldl' won't, it is pointed out that foldl starts building up
unevaluated thunks. So, apparently, these thunks are allocated on the
stack rather than on the heap with a pointer to the thunk on the stack.
(I understand that foldl' is asymptotically better than foldl
space-wise; that is irrelevant to my question.)

On the other hand, in this version that sums all the values in a tree

data Tree = Leaf Int | Node Tree Tree

sum :: Tree -> Int
sum t = sum' [t] 0
  where
sum' [] acc = acc
sum' (Leaf i : ts) acc = sum' ts $! (i + acc)
sum' (Node l r : ts) acc = sum' (l : r : ts) acc

we are building up a (potentially) large lists of trees yet to be
processed, but never run out of stack space. Apparently, the list is
built up on the heap rather than on the stack. 

What is the fundamental difference between these two examples? Why is
the list of trees yet to be processed allocated on the heap (with a
pointer on the stack, presumably) but the unevaluated thunks in the
foldl example allocated on the stack?

Thanks,

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


[Haskell-cafe] Re: Newbie Question: Using Haskell Functions in a C Program

2008-05-08 Thread Achim Schneider
Philip Müller <[EMAIL PROTECTED]> wrote:

> Is there a way to write some of the functions in Haskell and then use 
> them in my C code via some kind of interface?
> 
The beast you are looking for is called the FFI: Foreign Function
Interface.

C doesn't make IO any easier, though. More verbose and low-level, I
would say.


-- 
(c) this sig last receiving data processing entity. Inspect headers for
past copyright information. All rights reserved. Unauthorised copying,
hiring, renting, public performance and/or broadcasting of this
signature prohibited. 

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


Re: [Haskell-cafe] Induction (help!)

2008-05-08 Thread Daniel Fischer
Am Freitag, 9. Mai 2008 00:04 schrieb PR Stanley:
> You've got the right idea.
>   Paul: At long last! :-)
>   I should point out that it doesn't make sense to say p(Succ n) =
> Succ(p(n)),  p(x) represents some statement that is either true or
> false, so it doesn't make sense to say Succ(p(n)). .
>   Paul: okay, da capo: We prove/test through case analysis
> that the predicate p holds true for the first/starting case/element
> in the sequence. When dealing with natural numbers this could be 0 or
> 1. We try the formula with 0 and if it returns the desired result we
> move onto the next stage. If the formula doesn't work with 0 and so
> the predicate does not hold true for the base case then we've proved
> that it's a nonstarter.

Well, it might hold for all n >= 3. But you're right, if p doesn't hold for 
the base case, then it doesn't hold for _all_ cases.
>
> In the inductive step we'll make a couple of assumptions: we'll
> imagine that p(j). We'll also assume that p holds true for the
> successor of j - p(j+1).

No. In the induction step, we prove that
IF p(j) holds, THEN p(j+1) holds, too.
p(j) is the assumption, and we prove that *given that assumption*, p(j+1) 
follows.
Then we have proved 
(*) p(j) implies p(j+1), for all j.

If we already have established the base case, p(0), we have
p(0) and (p(0) implies p(1)) - the latter is a special case of (*) - from that 
follows p(1).
Then we have
p(1) and (p(1) implies p(2), again a special case of (*), therefore p(2).
Now we have p(2) and (p(2) implies p(3)), hence p(3) and so on.


> Then with the help of rules and the protocol available to us we'll
> try to establish whether the formula (f) gives us f(j) = f(j+1) - f(1)
> So, we know that the predicate holds for 0 or at least one element.
> By the way, could we have 3 or 4 or any element other than 0?

Sure, anything. Start with proving p(1073) and the induction proves p(n) for 
all n >= 1073, it does not say anything about n <= 1072.

> Anyway,
> p(0). Then we set out to find out if p holds for the successor of 0
> followed by the successor of the successor of 0 and so forth.
> However, rather than laboriously applying p to every natural number
> we innstead try to find out if f(j+1) - f(1) will take us back to
> fj). I think this was the bit I wasn't getting. The assumptions in
> the inductive step and the algebraic procedures are not to prove the
> formula or premise per se. That's sort of been done with the base
> case. Rather, they help us to illustrate that f remains consistent
> while allowing for any random element to be succeeded or broken down
> a successive step at a time until we reach the base/starting element/value.
> Okay so far?

Not quite, but close.
>
> Cheers
> Paul
>

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


[Haskell-cafe] Newbie Question: Using Haskell Functions in a C Program

2008-05-08 Thread Philip Müller

Hi,

I'm in the process of writing a C program, but I can't stop thinking 
about how some functions would be much nicer implemented in Haskell.


Is there a way to write some of the functions in Haskell and then use 
them in my C code via some kind of interface?


BTW yes, I have been thinking about writing the whole program in 
Haskell, but I just don't have the level of experience in Haskell 
programming for that, since it's really heavy on IO.


Thanks in advance for the answers!

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


Re: [Haskell-cafe] Induction (help!)

2008-05-08 Thread PR Stanley

You've got the right idea.
Paul: At long last! :-)
	I should point out that it doesn't make sense to say p(Succ n) = 
Succ(p(n)),  p(x) represents some statement that is either true or 
false, so it doesn't make sense to say Succ(p(n)). .

Paul: okay, da capo: We prove/test through case analysis
that the predicate p holds true for the first/starting case/element 
in the sequence. When dealing with natural numbers this could be 0 or 
1. We try the formula with 0 and if it returns the desired result we 
move onto the next stage. If the formula doesn't work with 0 and so 
the predicate does not hold true for the base case then we've proved 
that it's a nonstarter.


In the inductive step we'll make a couple of assumptions: we'll 
imagine that p(j). We'll also assume that p holds true for the 
successor of j - p(j+1).
Then with the help of rules and the protocol available to us we'll 
try to establish whether the formula (f) gives us f(j) = f(j+1) - f(1)
So, we know that the predicate holds for 0 or at least one element. 
By the way, could we have 3 or 4 or any element other than 0? Anyway, 
p(0). Then we set out to find out if p holds for the successor of 0 
followed by the successor of the successor of 0 and so forth. 
However, rather than laboriously applying p to every natural number 
we innstead try to find out if f(j+1) - f(1) will take us back to 
fj). I think this was the bit I wasn't getting. The assumptions in 
the inductive step and the algebraic procedures are not to prove the 
formula or premise per se. That's sort of been done with the base 
case. Rather, they help us to illustrate that f remains consistent 
while allowing for any random element to be succeeded or broken down 
a successive step at a time until we reach the base/starting element/value.

Okay so far?

Cheers
Paul

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


Re: [Haskell-cafe] The Monad.Reader (11) - Call for Copy

2008-05-08 Thread Donnie Jones
Speaking of old Monad.Reader issues... the wiki says,
"Issues 2 through 5  can be found on the
special tmrwiki – they haven't been included here for licensing reasons. I
hope to move over most of the content soon."

Any chance of those issues being moved over still?  I'd prefer to read the
older issues in pdf format, like the new issues.

Thank you!
__
Donnie Jones

On Thu, May 8, 2008 at 5:07 PM, Andrew Coppin <[EMAIL PROTECTED]>
wrote:

> Don Stewart wrote:
>
>> You should read through every issue ever published though -- there's a
>> lot of interesting lessons in TMR for the practical Haskeller.
>>
>>
>
> That would be entertaining sometime, but how many issues have ac... oh,
> wait... this is issue 11? Hmm, I hadn't realised that this publication was
> this new. I was thinking there were several hundred prior issues to wade
> through or something! :-.
>
>
> ___
> 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] The Monad.Reader (11) - Call for Copy

2008-05-08 Thread Andrew Coppin

Don Stewart wrote:

You should read through every issue ever published though -- there's a
lot of interesting lessons in TMR for the practical Haskeller.
  


That would be entertaining sometime, but how many issues have ac... oh, 
wait... this is issue 11? Hmm, I hadn't realised that this publication 
was this new. I was thinking there were several hundred prior issues to 
wade through or something! :-.


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


Re: [Haskell-cafe] The Monad.Reader (11) - Call for Copy

2008-05-08 Thread Don Stewart
andrewcoppin:
> Wouter Swierstra wrote:
> >
> >On 7 May 2008, at 19:56, Andrew Coppin wrote:
> >
> >>Wouter Swierstra wrote:
> >>>Please consider writing something for the next issue of The 
> >>>Monad.Reader.
> >>
> >>You know, I'm actually tempted to do just that...
> >
> >Please do! We've had lots of excellent articles written by people who 
> >were just learning Haskell. Sometimes a beginner's perspective can be 
> >quite refreshing. Feel free to contact me personally if you have any 
> >questions.
> 
> Without reading through every issue ever published, do you have any 
> specific examples of this that I [or anybody else in cafe] could take a 
> look at?

You should read through every issue ever published though -- there's a
lot of interesting lessons in TMR for the practical Haskeller.

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


Re: [Haskell-cafe] Re: Interesting critique of OCaml

2008-05-08 Thread Darrin Thompson
2008/5/8 Donnie Jones <[EMAIL PROTECTED]>:
> I would be interested to see an article on Haskell in the same light as this
> Ocaml article, aka a constructive criticism of Haskell.
>

http://www.drmaciver.com/2008/02/tell-us-why-your-language-sucks/

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


Re: [Haskell-cafe] The Monad.Reader (11) - Call for Copy

2008-05-08 Thread Wouter Swierstra
Without reading through every issue ever published, do you have any  
specific examples of this that I [or anybody else in cafe] could  
take a look at?


The following two articles spring to mind:

  * Kenneth Hoste wrote a gtk2hs tutorial, after having just started  
using it: http://www.haskell.org/sitewiki/images/9/9d/TMR-Issue1.pdf


  * Graham Klyne wrote some notes on learning Haskell: 
http://www.haskell.org/tmrwiki/LearningHaskellNotes

Best,

  Wouter


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


Re: [Haskell-cafe] A Cabal problem

2008-05-08 Thread Mario Blazevic

Duncan Coutts wrote:

On Tue, 2008-05-06 at 09:43 -0400, Mario Blazevic wrote:

Trevor Elliott wrote:



Cabal doesn't pass the --main-is option, I believe because it is
specific to GHC.  What you could do is add this flag in the ghc-options
field of your executable in the cabal file, like this:

ghc-options: --main-is Shell
	That worked like charm, except the two dashes should be one (my 
mistake). Thank you.


Note that hackage will reject packages that use "ghc-options: -main-is"
with the message that it is not portable. The rationale is that unlike
other non-portable extensions, it is easy to change to make it portable:
http://hackage.haskell.org/trac/hackage/ticket/179
If you want to argue for supporting this ghc extension and/or implement
support (possibly with workaround support for the other haskell
implementations) then please do comment on the above ticket.

Duncan



	After some experimentation, I've changed my opinion and now agree with 
the current behaviour. I had the impression that every Haskell module 
had to reside in a same-named file. While this appears to be true for 
*imported* modules and GHC (hence my mistaken impression), the Haskell 
98 standard does not specify anything of the sort. In case of the 
top-level module, GHC (as well as the standard) allows it to reside in a 
file of any name. So the only reasonable use for -main-is option, as I 
see it, is to allow multiple small main modules residing in the same 
file, and I guess that's not likely to be encountered in a package.



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


[Haskell-cafe] Re: I am new to haskell

2008-05-08 Thread Bjorn Buckwalter
Bjorn Buckwalter  gmail.com> writes:

> I found the "Gentle Introduction..." mentioned elsewhere in this thread to be
> not-so-gentle as described on the tutorials wiki page. I'd avoid it unless
> you're already comfortable with functional programming.

Let me modify that statement. I'd avoid it until you've made your way through
one or two of the other tutorials, and then give it a good reading. It's an
excellent "introduction", only not for beginners. ;)

-Bjorn

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


[Haskell-cafe] Re: I am new to haskell

2008-05-08 Thread Bjorn Buckwalter
Ambrish Bhargava  gmail.com> writes:
> Hi All,I am new to Haskell. Can anyone guide me how can I start on it (Like
getting binaries, some tutorials)?Thanks in advance.-- Regards,Ambrish Bhargava


Ambrish,

When I started learning Haskell I had no previous exposure to functional
programming. The sources I found most useful were Hal Daume III's "Yet Another
Haskell Tutorial" and Eric Etheridge's "Haskell Tutorial for C Programmers",
both linked to from the tutorials wiki page:

  http://www.haskell.org/haskellwiki/Tutorials

I found the "Gentle Introduction..." mentioned elsewhere in this thread to be
not-so-gentle as described on the tutorials wiki page. I'd avoid it unless
you're already comfortable with functional programming.

Good luck!

-Bjorn


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


Re: [Haskell] [Haskell-cafe] Help with polymorphic functions

2008-05-08 Thread Reinier Lamers
Op Thursday 08 May 2008 21:10:08 schreef Wei Yuan Cai:
> shift is defined as "a -> Int -> a"
It's not. It's defined as "(Bits a) => a -> Int -> a" or something along those 
lines. So there is a restriction that the type a must be a member of the Bits 
typeclass.

Because "test" is essentially just "shift", its type must also be  "(Bits a) 
=> a -> Int -> a".

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


Re: [Haskell] [Haskell-cafe] Help with polymorphic functions

2008-05-08 Thread Bulat Ziganshin
Hello Wei,

Thursday, May 8, 2008, 11:10:08 PM, you wrote:

> test :: a -> Int -> a

> shift is defined as "a -> Int -> a"

not exactly ;)  this type signature is given inside class Bits, where
'a' isn't a free variable (as in standalone signature declaration),
but means 'a' from type class header:

class Num a => Bits a where
shift :: a -> Int -> a

so, this declaration is equivalent to the following standalone one:

shift :: (Bits a) =>  a -> Int -> a


from the common sense POV, you can't shift *ANY* type 'a', but only
types that belong to the Bits class. so, shift cannot have signature
w/o class, and the same remains true for `test`


-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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


Re: [Haskell-cafe] The Monad.Reader (11) - Call for Copy

2008-05-08 Thread Andrew Coppin

Wouter Swierstra wrote:


On 7 May 2008, at 19:56, Andrew Coppin wrote:


Wouter Swierstra wrote:
Please consider writing something for the next issue of The 
Monad.Reader.


You know, I'm actually tempted to do just that...


Please do! We've had lots of excellent articles written by people who 
were just learning Haskell. Sometimes a beginner's perspective can be 
quite refreshing. Feel free to contact me personally if you have any 
questions.


Without reading through every issue ever published, do you have any 
specific examples of this that I [or anybody else in cafe] could take a 
look at?


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


[Haskell-cafe] Workshop on Generic Programming: Call for Papers (co-located w/ ICFP08)

2008-05-08 Thread Matthew Fluet (ICFP Publicity Chair)
   CALL FOR PAPERS

 Workshop on Generic Programming 2008

Victoria, Canada, 20th September 2008

 http://www.comlab.ox.ac.uk/ralf.hinze/wgp2008/cfp.{html,pdf,ps,txt}

 The Workshop on Generic Programming is sponsored by ACM SIGPLAN
 and forms part of ICFP 2008.  Previous Workshops on Generic
 Programming have been held in Marstrand (affiliated with MPC),
 Ponte de Lima (affiliated with MPC), Nottingham (informal
 workshop), Dagstuhl (IFIP WG2.1 Working Conference), Oxford
 (informal workshop), Utrecht (informal workshop), and Portland
 (affiliated with ICFP).

Scope
-

Generic programming is about making programs more adaptable by making
them more general.  Generic programs often embody non-traditional
kinds of polymorphism; ordinary programs are obtained from them by
suitably instantiating their parameters. In contrast with normal
programs, the parameters of a generic program are often quite rich in
structure; for example they may be other programs, types or type
constructors, class hierarchies, or even programming paradigms.

   Generic programming techniques have always been of interest, both
to practitioners and to theoreticians, but only recently have generic
programming techniques become a specific focus of research in the
functional and object-oriented programming language communities. This
workshop will bring together leading researchers in generic
programming from around the world, and feature papers capturing the
state of the art in this important emerging area.

   We welcome contributions on all aspects, theoretical as well as
practical, of

   o adaptive object-oriented programming,
   o aspect-oriented programming,
   o component-based programming,
   o generic programming,
   o meta-programming,
   o polytypic programming,
   o programming with modules, and so on.

Submission details
--

   Deadline for submission:30th June 2008
   Notification of acceptance: 14th July 2008
   Final submission due:   28th July 2008
   Workshop:   20th September 2008

Authors should submit papers, in PostScript or PDF format, formatted
for A4 paper, to Ralf Hinze ([EMAIL PROTECTED]) or Don Syme
([EMAIL PROTECTED]) by 30th June 2008. The length should be
restricted to 12 pages in standard (two-column, 9pt) ACM. Accepted
papers are published by the ACM and will additionally appear in the
ACM digital library.

Programme committee
---

Ralf Hinze (co-chair)University of Oxford
Patrik Jansson   Chalmers University
Andrew Lumsdaine Indiana University
Conor McBrideUniversity of Nottingham
Adriaan MoorsUniversiteit Leuven
Fritz Ruehr  Willamette University
Tim Sheard   Portland State University
Don Syme (co-chair)  Microsoft Research
Todd Veldhuizen  University of Waterloo
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Interesting critique of OCaml

2008-05-08 Thread Donnie Jones
Hello,
I pasted a copy of the article below for those that cannot access the site.

I would be interested to see an article on Haskell in the same light as this
Ocaml article, aka a constructive criticism of Haskell.

Enjoy!
__
Donnie

### Begin Article ###
Why Ocaml Sucks

Published by Brian  at
6:49 pm under Functional Languages: Ocaml,
Haskell

One of the ways to not fall into the blub fallacy is to regularly consider
those ways in which your favorite language is inferior, and could be
improved- preferrably radically improved. Now, it should come as a surprise
to no one that my favorite language is (currently) Ocaml. So as an
intellectual exercise I want to list at least some of the ways that Ocaml
falls short as a language.

I will note that if you use this post as a reason to *not* use Ocaml, you
are a fool and are missing the point of this post. With the
*possible*exception of Haskell, no other language I know of comes
close to getting all
the things right that Ocaml gets right.

So, with that in mind, let's begin.


   1. Lack of Parallelism

   In case you haven't guessed it from reading this blog, I think
   parallelism is going to be the big problem for the next decade. And while
   Ocaml does have threads, it also has a big ol' global interpreter lock, so
   that only one thread can be executing Ocaml code at a time. Which severely
   limits the utility of threads, and severely limits the ability of Ocaml
   programmers to take advantage of multiple cores. Now, to give the INRIA team
   credit, the reason they have for this is a good one- we (programmers) still
   don't know for sure how to write multithreaded code safely (I have my
   suspicions, but I have no proof), and we had even less of an idea a decade
   and a half ago when the fundamentals of Ocaml were being decided. And
   supporting multithreaded code slows down the garbage collector. And, a
   decade and a half ago, multithreaded code was a lot less important, and
   multicore systems were rare and expensive. So this is mainly just Ocaml
   showing it's age. But still, if I were to pick the biggest shortcomming of
   Ocaml, this would be it.


   2. Printf

   You know what? Printf was a bad idea for C- having this special
   domain-specific language in what looks like strings to control formatting.
   It's even worse in Ocaml, where you have to add special kludges to the
   compiler to support it (at least the way Ocaml did it- there are smarter
   ways  that don't require compiler
   kludges). You might think that "%3d" is a string in Ocaml, and sometimes
   you'd be right. But sometimes it's a (int -> '_a, '_b, '_c, '_a) format4.
   This horrid type (which is *not* a string) is necessary to encode the
   types of the arguments printf needs to be passed it.

   The one thing I know of that C++ did better than Ocaml was ditching
   printf. And the idea of iostreams even isn't that bad- except for the fact
   that they encouraged generations of C++ programmers to abuse operator
   overloading (hint to Bjarne Stroustrup: << and >> are not the I/O operators,
   they're the bit shift operators!), and they made the iostream classes
   exceptionally difficult to inherit from or extend. But a combination of C++
   style iostream operators and Java style iostream classes would have worked
   so much better, and not required hacking the compiler. An even better idea
   might be some variant of functional unparsing
   .

   3. Lack of multi-file modules

   Ocaml has an exceptionally powerfull and flexible module and functor
   system, which stops rather annoyingly at the file level. Files are modules,
   and files (and modules) can contain other modules within them, but you can't
   collect several files into one big multi-file module. You especially can't
   say that certain files, while they may be visible to other modules within
   the multi-file module, aren't visible outside the multi-file module. This is
   especially useful if you want to factor out common base functionality from a
   library of modules into a shared module, but not productize it for export to
   the outside world. This limits the ability of the programmers to correctly
   structure large projects.

   The -for-pack arguments help fix a lot of this, sorta- but they require
   smarts in the build system and generally special .mli files to control
   visibility. It can be done, but it's not clean- it makes the build process a
   lot more complex, and important information about which files are externally
   visible or not is contained somewhere that is not in the source code. This
   could certainly be done a hell of a lot better than it is.


   4. Mutable data

   Mutable data is both a blessing and a curse. It is a

Re: [Haskell-cafe] Random numbers / monads - beginner question

2008-05-08 Thread Dan Weston

Henning Thielemann wrote:


On Thu, 8 May 2008, Madoc wrote:


minValue = 0::Int
maxValue = 1000::Int

normalize a | a < minValue = minValue
   | a > maxValue = maxValue
   | otherwise = a



normalize' = min maxValue . max minValue


There is a curiosity here. The functions normalize and normalize' are 
extensionally equal only because minValue <= maxValue, but intensionally 
different. The intensional equivalent is to reverse order of composition:


normalize'' = max minValue . min maxValue

which remains equal to to normalize whatever the values of minValue and 
maxValue.


That the order of composition (or of guarded expressions) matters 
conditionally base on its parameters is reason enough for the original 
poster to decide what the "right answer" should be if maxValue < 
minValue. These corner cases are often where future bugs lie dormant. My 
choice would be:


normalize'''= max trueMin . min trueMax
  where trueMin = min minValue maxValue
trueMax = max minValue maxValue

Now the function makes no assumptions about external values. This is no 
less efficient than before, since trueMin and trueMax are CAFs evaluated 
only once.



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


Re: [Haskell-cafe] Re: Interesting critique of OCaml

2008-05-08 Thread Andrew Coppin

Chad Scherrer wrote:

PS - the link now gives a "500 server error" - did our traffic overwhelm it? Is
the cafe the next slashdot? ;)
  


Hell, I can't even get a TCP SYN-ACK packet out of it... :-/

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


Re: [Haskell-cafe] Re: Interesting critique of OCaml

2008-05-08 Thread Andrew Coppin

Achim Schneider wrote:

Some years or decades ahead, perhaps Haskell will not be able to avoid
being successful anymore, and that is the time where you'll see things
that look like Java, feel like Java, work like Java, but still use a
Haskell RTS.
  


I'm told they're calling it F#...

[No, I can't verify the truth of that claim. But every time I mention 
Haskell, everybody goes "Haskell is obsolete. Everybody who even *wants* 
functional programming in the first place will just use F# instead. The 
end."]


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


[Haskell-cafe] Re: Interesting critique of OCaml

2008-05-08 Thread Achim Schneider
Chad Scherrer <[EMAIL PROTECTED]> wrote:

> Don Stewart  galois.com> writes:
> 
[Stuff where I totally agree]
>
> Now, I don't know much about lisp, but aren't code transformations
> like this the whole point of macros? What makes is difficult to do
> the same thing in this context?
> 
Proof of correctness, or even a graspable notion of correctness for the
whole semantics of the language. If you consider that hygienic macros
(that is, macros that don't make a mess of every concept you have of
"namespace") were introduced quite late, you might get a grasp on how
bravely and hackish they were designed.

> What about object-oriented languages? The problem with step 1 in the
> argument is that it's already cast in a functional-programming
> framework. Is there a way to recast it so OOP could play?
> 
Yes, I suppose so, but you'll be left with Haskell with an OOP Syntax,
and a style of OOP that uses Objects mainly as closures, which isn't a
thing OOP coders regularly, or at all, do, to get the granularity of
replacements that is necessary to consider them useful in the first
run.

Some years or decades ahead, perhaps Haskell will not be able to avoid
being successful anymore, and that is the time where you'll see things
that look like Java, feel like Java, work like Java, but still use a
Haskell RTS.


-- 
(c) this sig last receiving data processing entity. Inspect headers for
past copyright information. All rights reserved. Unauthorised copying,
hiring, renting, public performance and/or broadcasting of this
signature prohibited. 

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


[Haskell-cafe] Re: [Haskell] Re: ANN: Haddock version 2.1.0

2008-05-08 Thread David Waern
2008/5/8 Simon Marlow <[EMAIL PROTECTED]>:
> So basically you want to run a lexer over the source again to collect all
> the comments?

Yes.

> You really want to use GHC's lexer, because otherwise you
> have to write another lexer.

I don't mind writing a lexer that just collects the comments. It
should be simpler than a full Haskell lexer, right? It wouldn't need
to handle layout, for instance. Using GHC is also a good option.

> So a flag to GHC's lexer that says whether it
> should return comments or not seems like a reasonable way to go.  But if
> you're doing that, you might as well have the parser collect all the
> comments off to the side during parsing, to avoid having to lex the file
> twice, right?

Yes.

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


[Haskell-cafe] Re: Interesting critique of OCaml

2008-05-08 Thread Chad Scherrer
Don Stewart  galois.com> writes:
[interesting quote...]
> Which I think really captures the joy of being able to write algebraic
> and data structure transformations, via rewrite rules, without having to
> extend the compiler -- all thanks to purity, laziness, and static
> typing.

This makes me wonder... Rewrite rules are certainly effective, and seem to be a
good place to point (one of many, of course) when asked why you'd want a 
language with Haskell's characteristics. It seems like there should be an
argument to this effect:

1. You'd like be able to declare compile-time transformations like
  map f . map g = map (f . g)
without messing with the compiler

2. For x in [purity, laziness, static typing, higher-order functions]
  If you don't have x, here's what goes wrong (or can go wrong)

3. Of the very few languages with these characteristics, Haskell is the most
widely-used, and the most actively developed and researched.

Now, I don't know much about lisp, but aren't code transformations like this the
whole point of macros? What makes is difficult to do the same thing in this 
context?

What about object-oriented languages? The problem with step 1 in the argument is
that it's already cast in a functional-programming framework. Is there a way to
recast it so OOP could play?

Thanks,
Chad

PS - the link now gives a "500 server error" - did our traffic overwhelm it? Is
the cafe the next slashdot? ;)

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


Re: [Haskell-cafe] Using Template Haskell to make type-safe database access

2008-05-08 Thread Mads Lindstrøm
Hi Wouter,

Wouter Swierstra wrote:

> Nice! I have to admit, it's much nicer than I expected it to be. Just  
> out of curiousity, what happens when you write:
> 
> selectTupleList :: Connection -> IO [Integer]
> 
> instead of
> 
> selectTupleList :: Connection -> IO [(Integer, String, String)]
> 
> What kind of error message do you get? More specifically, is this  
> error caught statically or dynamically.

The type annotation in UseSqlExpr.hs was just for the reader. The
compiler can infer the types completely. Thus when I make the suggested
change I get a compile time error. It looks like this:

UseSqlExpr.hs:27:6:
Couldn't match expected type `Integer'
   against inferred type `(Integer, String, String)'
  Expected type: IO [Integer]
  Inferred type: IO [(Integer, String, String)]
In the expression:
(return
   $ (map
(\ [x0[a2ZY], x1[a2ZZ], x2[a300]]
 -> (readInteger x0[a2ZY],
 readString x1[a2ZZ],
 readString x2[a300]))
rows[a2ZX]))
In the expression:
do rows[a2ZX] <- fetchRows
   dsn[a2ZW]
   ['S', 'E', 'L', 'E', 'C', 'T', ' ', 'u', 's', 'e', 
'r', '_', 'i',
'd', ',', ' ', 'u', 's', 'e', 'r', '_', 'n', 'a', 
'm', 'e', ',',
' ', 'u', 's', 'e', 'r', '_', 'r', 'e', 'a', 'l', 
'_', 'n', 'a',
'm', 'e', ' ', 'F', 'R', 'O', 'M', ' ', 'u', 's', 
'e', 'r', ';']
   (return
  $ (map
   (\ [x0[a2ZY], x1[a2ZZ], x2[a300]]
-> (readInteger x0[a2ZY],
readString x1[a2ZZ],
readString x2[a300]))
   rows[a2ZX]))
make: *** [all] Fejl 1

> 
> The only other limitation I can think of, would be in the situation  
> where you don't have compile-time access to the database, e.g.  
> developing software for a client with a database that can only be  
> accessed from their intranet. I have no idea how much of a limitation  
> that is.

True, but this limitation is only relevant when you do not have access
to the production database or a database with identical metadata. How
often do people develop like that? How are they testing? I have a hard
time picturing a setup without a test database with identical metadata
to the production database.

> >> Perhaps I should explain my own thoughts on the subject a bit better.
> >> I got interested in this problem because I think it makes a nice
> >> example of dependent types "in the real world" - you really want to
> >
> > But won't you end up implementing all the functionality of an SQL
> > parser? While possible, it does seem like a huge job. With a TH  
> > solution
> > you will safe a lot of work.
> 
> Yes - but parsing the result of an SQL describe statement is pretty  
> easy.
ok.

> 
> > A library that
> > will be a lot more complex to learn than what I am proposing (assuming
> > the developer already knows SQL).
> 
> Hmm. This is a rather sticky point. One might also argue that Haskell  
> developers have to learn SQL to use the solution you propose. I'm not  
> particularly convinced. Both approaches have their merits I think.

Yes. I was _not_ making what you could call a strong argument. I was
assuming that most (Haskell) developers knew SQL anyway. I have no data
to back it up. Just my gut feeling.

To be fair I should mention a couple of drawbacks with the TH-based
approach. While SQL got static typing, it is not really as powerful as
it could be. For example if you do "select sum(...) from ..." the type
system will tell you that a set of values are returned. In reality this
set will never have more than one member. Your proposal would be able to
return a Float in stead of a [Float].

Another advantage your proposal (and disadvantage of the TH based one)
would be that it can abstract over variances in different database
implementation. That is, you could translate to SQL depending on SQL
backend. This would be really nice. But I guess it would also be a big
task.

> 
> Anyhow - nice work! Have you asked Bjorn Bringert what he thinks? He's  
> a really clever and approachable guy - and he knows a lot more about  
> interfacing with databases than I do.
> 
> Kind regards,
> 
>Wouter

/Mads Lindstrøm



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


Re: [Haskell-cafe] I am new to haskell

2008-05-08 Thread Darrin Thompson
On Thu, May 8, 2008 at 2:59 AM, Benjamin L. Russell
<[EMAIL PROTECTED]> wrote:
>  * Kees Doets and Jan van Eijck: The Haskell Road to Logic, Maths and 
> Programming,

As someone approaching haskell with very rusty math skills, this book
has been invaluable. My haskell skills are (mostly) beyond what the
text is covering, but I'm dutifully working through the math problems
as doing it (partway through chapter 4 now, yay!) has sharpened my
thinking already. The end result is that I can already sort of read
some of the Haskell research papers like the Fusion one.

Also, Jan van Eijck is pretty responsive and untangled my mind from
time to time.

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


Re: [Haskell-cafe] IO Help

2008-05-08 Thread Mark Wallsgrove

Thank you all for your help, you have been invaluable

Thomas Davie wrote:


On 8 May 2008, at 16:31, Mark Wallsgrove wrote:


Was there? I have been google'ing that problem for ages..

Just one more thing. I have to make a menu system where the user 
chooses what functionality they want. Because you cannot change a 
value once it is set I have used recursion so that when something 
changes it then calls the menu back up. I feel this is way to memory 
consuming. Is there another way?


While this method feels like it should consume lots of memory, it in 
fact doesn't.  Remember that you're dealing with a graph machine, and 
that no stack is maintained of all the calls you've made.  The garbage 
collector will simply follow you through the menu system clearing up the 
memory behind you.


Bob



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


Re: [Haskell-cafe] IO Help

2008-05-08 Thread Thomas Davie


On 8 May 2008, at 16:31, Mark Wallsgrove wrote:


Was there? I have been google'ing that problem for ages..

Just one more thing. I have to make a menu system where the user  
chooses what functionality they want. Because you cannot change a  
value once it is set I have used recursion so that when something  
changes it then calls the menu back up. I feel this is way to memory  
consuming. Is there another way?


While this method feels like it should consume lots of memory, it in  
fact doesn't.  Remember that you're dealing with a graph machine, and  
that no stack is maintained of all the calls you've made.  The garbage  
collector will simply follow you through the menu system clearing up  
the memory behind you.


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


Re: [Haskell-cafe] IO Help

2008-05-08 Thread Mark Wallsgrove

Was there? I have been google'ing that problem for ages..

Just one more thing. I have to make a menu system where the user chooses 
what functionality they want. Because you cannot change a value once it 
is set I have used recursion so that when something changes it then 
calls the menu back up. I feel this is way to memory consuming. Is there 
another way?


CODE:

main catalogue playlist:
 x = choose option
 passtofunction x


passtofunction value:
 function1 1 = main (functionName value) playlist
 function2 2 = main catalogue (functionName value)

Henning Thielemann wrote:


On Thu, 8 May 2008, Mark Wallsgrove wrote:


Thank you very much for your fast response!

Ok, that is now changed, but everything else in my program is 
expecting Catalogue without IO. Is there a way to change IO Catalogue 
into Catalogue?


Btw. there was a nice article precisely about the issue "How to get rid 
of the IO?" in the old Hawiki. What is the progress in bringing back 
Hawiki?





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


Re: [Haskell-cafe] IO Help

2008-05-08 Thread Henning Thielemann


On Thu, 8 May 2008, Mark Wallsgrove wrote:


Thank you very much for your fast response!

Ok, that is now changed, but everything else in my program is expecting 
Catalogue without IO. Is there a way to change IO Catalogue into Catalogue?


Btw. there was a nice article precisely about the issue "How to get rid of 
the IO?" in the old Hawiki. What is the progress in bringing back Hawiki?


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


[Haskell-cafe] List questions

2008-05-08 Thread Achim Schneider
<[EMAIL PROTECTED]> wrote:

> Hi I have a bit of a dilemma.I have a list of lists, eg,
> [[1,2,3],[4,5,6],[7,8,9]]. Imagine they represent a grid with 0-2 on
> the x axis and 0-2 on the y axis, eg, (0,0) is 1, (1,0) is 2, (2,1)
> is 6, etc and (2,3) is 9. I want to be able to put in the list of
> lists, and the (x,y) coordinate, and return the value. 
> 
select x y ys = (ys !! y) !! x


> Also, I need to be able to replace a value in the list. Eg, if I
> wanted to replace (2,3) with 100, then the output of the expression
> would be [[1,2,3],[4,5,6],[7,8,100]].
>
you can't replace it, you can only construct a new list: Your function
will likely be of the type

replace :: Int -> Int -> a -> [[a]] -> [[a]]

I won't give the answer here, as that would spoil all of the fun
and delight you'll have while browsing through the Prelude and
Data.List and see how much duct tape there's around, waiting to be
used, plus I'd have to open a new file as ghci doesn't support
multi-line functions.

-- 
(c) this sig last receiving data processing entity. Inspect headers for
past copyright information. All rights reserved. Unauthorised copying,
hiring, renting, public performance and/or broadcasting of this
signature prohibited. 

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


Re: [Haskell-cafe] (no subject)

2008-05-08 Thread Daniel Fischer
Am Donnerstag, 8. Mai 2008 15:36 schrieb [EMAIL PROTECTED]:
> Hi I have a bit of a dilemma.I have a list of lists, eg,
> [[1,2,3],[4,5,6],[7,8,9]]. Imagine they represent a grid with 0-2 on the x
> axis and 0-2 on the y axis, eg, (0,0) is 1, (1,0) is 2, (2,1) is 6, etc and
> (2,3) is 9. I want to be able to put in the list of lists, and the (x,y)
> coordinate, and return the value. 
>
> Also, I need to be able to replace a value in the list. Eg, if I wanted to
> replace (2,3) with 100, then the output of the expression would be
> [[1,2,3],[4,5,6],[7,8,100]].
>
> Any help would be great!

To get the value at a position, look up (!!)
To replace a value, you could use zipWith

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


Re: [Haskell-cafe] IO Help

2008-05-08 Thread Henning Thielemann


On Thu, 8 May 2008, Mark Wallsgrove wrote:


Thank you very much for your fast response!

Ok, that is now changed, but everything else in my program is expecting 
Catalogue without IO. Is there a way to change IO Catalogue into Catalogue?


Yes, but you do not want that. You will go on writing functions which 
consume Catalogue and finally you will apply a Catalogue function in the 
IO monad which does all the work at once.

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


[Haskell-cafe] Thanks for the help! (Random numbers / monads - beginner question)

2008-05-08 Thread Madoc

Thanks for helping me! Your fast and accurate responses helped me to solve
this issue. I am not so angry at IO any more. You showed me more than one
way in which I can solve the problem.

In addition, the answers to the other thread "IO Help" helped me too. It
seems that Mr. Wallsgrove had a very similar question at the same time.

Thanks very much, this was really great for me!
-- 
View this message in context: 
http://www.nabble.com/Random-numbers---monads---beginner-question-tp17124380p17125957.html
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] Random numbers / monads - beginner question

2008-05-08 Thread Sebastian Sylvan
2008/5/8 Madoc <[EMAIL PROTECTED]>:

> Hello,
>
> I am just learning Haskell. Now, I encountered something that I cannot
> solve by myself. Your advice will be greatly appreciated.
>
> Given a list of numbers, I want to modify each of those numbers by adding a
> random offset. However, each such modified number shall stay within certain
> bounds, given by the integers minValue and maxValue. After that, I want to
> continue computation with the resulting list of type [Int]. But for
> demonstration, I made a program that just prints out the list:
>
> import IO; import Random
>
> minValue = 0::Int
> maxValue = 1000::Int
>
> normalize a | a < minValue = minValue
> | a > maxValue = maxValue
> | otherwise = a
>
> modify a = do
>   offset <- randomRIO(-100::Int, 100)
>   return(normalize(a + offset))
>
> main = putStrLn $ show $ map (modify) [0, 200, 400, 600, 800, 1000]
>
> This program will not compile. GHC complains:
>
> test.hs:14:18:
> No instance for (Show (IO Int))
>   arising from a use of `show' at test.hs:14:18-21
> Possible fix: add an instance declaration for (Show (IO Int))
> In the first argument of `($)', namely `show'
> In the second argument of `($)', namely
> `show $ map (modify) [0, 200, 400, 600, ]'
> In the expression:
>   putStrLn $ show $ map (modify) [0, 200, 400, 600, ]
>
> I understand that the result of the modify function is not an Int, as I
> would like to have it, but instead IO Int, and that cannot be applied to
> show. (I also did not quite understand why I need those brackets around
> the return value of the modify value. It won't compile if I leave them
> out, but I can accept that for now.)
>
> I also figured out how to generate a modified list of type [IO Int] and of
> type IO [Int]. However, I could not find out how to completely get rid of
> the IO monad and just get a mofied list of type [Int], which is what I
> really want.
>
> Please, do You have any advice for me? I tried for some hours, and now I am
> really angry at that IO monad that sticks to my pretty integers like glue!
>
> Also, any comment on the programming style and how I could achive my goals
> easier would be appreciated. (I left out comments and function types for the
> sake of brevity.)
>

You should use newStdGen to produce a random generator, then randomRs to
produce a list of random numbers (without using IO!).

But if you really want this version with IO interspersed through the
algorithm to work, then something like this should do it (uncompiled):

main = do
 xs <- mapM  (modify) [0, 200, 400, 600, 800, 1000]
 putStrLn $ show $ xs

The only way to "get rid of the IO monad", is to use "<-" to bind it to a
value from within the IO monad.



-- 
Sebastian Sylvan
+44(0)7857-300802
UIN: 44640862
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] IO Help

2008-05-08 Thread Stuart Cook
On Thu, May 8, 2008 at 10:59 PM, Mark Wallsgrove
<[EMAIL PROTECTED]> wrote:
> Thank you very much for your fast response!
>
> Ok, that is now changed, but everything else in my program is expecting
> Catalogue without IO. Is there a way to change IO Catalogue into Catalogue?

Suppose I have a function "readFile" of type String -> IO String, and
a function "read" of type String -> Catalogue. How can I feed the
output of the first function into the second function, when that pesky
"IO" is in my way? Perhaps I would write something that looks like
this:

  loadData :: String -> IO Catalogue
  loadData fileName = do
  x <- readFile fileName
  return (read x :: Catalogue)

Even though the expression "readFile fileName" has type IO String, the
variable "x" bound on the third line has type String. This means that
I can pass it into "read" without any problems.

Eventually you'll learn about things like (>>=) and "liftM", which can
be used to write this in a simpler form, but hopefully this will get
you going for now.


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


[Haskell-cafe] (no subject)

2008-05-08 Thread u4538637
Hi I have a bit of a dilemma.I have a list of lists, eg, 
[[1,2,3],[4,5,6],[7,8,9]]. Imagine they represent a grid with 0-2 on the x axis 
and 0-2 on the y axis, eg, (0,0) is 1, (1,0) is 2, (2,1) is 6, etc and (2,3) is 
9. I want to be able to put in the list of lists, and the (x,y) coordinate, and 
return the value. 

Also, I need to be able to replace a value in the list. Eg, if I wanted to 
replace (2,3) with 100, then the output of the expression would be 
[[1,2,3],[4,5,6],[7,8,100]].

Any help would be great!
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] IO Help

2008-05-08 Thread Daniel Fischer
Am Donnerstag, 8. Mai 2008 14:59 schrieb Mark Wallsgrove:
> Thank you very much for your fast response!
>
> Ok, that is now changed, but everything else in my program is expecting
> Catalogue without IO. Is there a way to change IO Catalogue into Catalogue?
>
Not a recommendable way. But there's no need to, your programme will probably 
look like

main = do
args <- getArgs
let realArgs = parseArgs args
catalogue <- loadData
doSomething realArgs catalogue

and doSomething might e.g. construct an updated catalogue and write it to a 
file.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] IO Help

2008-05-08 Thread Mark Wallsgrove

Thank you very much for your fast response!

Ok, that is now changed, but everything else in my program is expecting 
Catalogue without IO. Is there a way to change IO Catalogue into Catalogue?


Henning Thielemann wrote:


On Thu, 8 May 2008, Mark Wallsgrove wrote:

Problem now is reading the data back into the program. When I read the 
data
back into the program it comes as IO [Track]. This is the code I have 
been

using to load the data:


loadData :: String -> Catalogue
loadData fileName = do x <- readFile fileName
  return (read x :: Catalogue)


type should be

  loadData :: String -> IO Catalogue


But using plainly 'read' may not satisfy you, because the program will 
abort unrecoverably if the file has corrupt content. You may want to use 
'reads' and check manually if parsing was successful:


case reads x of
   [(cat, "")] -> return cat
   _ -> fail "corrupt file content"



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


Re: [Haskell-cafe] IO Help

2008-05-08 Thread Henning Thielemann


On Thu, 8 May 2008, Mark Wallsgrove wrote:


Problem now is reading the data back into the program. When I read the data
back into the program it comes as IO [Track]. This is the code I have been
using to load the data:


loadData :: String -> Catalogue
loadData fileName = do x <- readFile fileName
  return (read x :: Catalogue)


type should be

  loadData :: String -> IO Catalogue


But using plainly 'read' may not satisfy you, because the program will 
abort unrecoverably if the file has corrupt content. You may want to use 
'reads' and check manually if parsing was successful:


case reads x of
   [(cat, "")] -> return cat
   _ -> fail "corrupt file content"
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] IO Help

2008-05-08 Thread Mark Wallsgrove

Hey,

I am studying Haskell as a unit at University. I find the concept and design
idea's of Haskell interesting but I am finding my self struggling to
understand the relationship between the normal state and IO state of
Haskell. This is my situation:

I have created 12 functions for a program which take in two types:


type Catalogue = [Track]
type Playlist = [Track]


The definition for track is as follows:


-- Track = ArtistDetails Title Length PCount
data Track = Track ArtistType String Float Int
 deriving (Show,Eq,Read)

-- Popular = Artist | Composor Performer
data ArtistType = Popular String | Classical String String
 deriving (Show,Eq,Read)


I have managed to save the data to a file using this code:


--Saving Data
saveData :: String -> Catalogue -> IO()
saveData fileName catalogue = writeFile fileName (show catalogue)


Problem now is reading the data back into the program. When I read the data
back into the program it comes as IO [Track]. This is the code I have been
using to load the data:


loadData :: String -> Catalogue
loadData fileName = do x <- readFile fileName
   return (read x :: Catalogue)


I think I have missed a trick some where or I am using IO wrong, I really
don't know. I believe it is the latter. I have been told that my definition
for the function is wrong and that I should use the lazy approach to fix the
problem. But this still leaves me with IO [Track].

Could someone inform me on what I am doing wrong?

Thank you in advance
Smoky
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Random numbers / monads - beginner question

2008-05-08 Thread Henning Thielemann


On Thu, 8 May 2008, Madoc wrote:


Given a list of numbers, I want to modify each of those numbers by adding a
random offset. However, each such modified number shall stay within certain
bounds, given by the integers minValue and maxValue. After that, I want to
continue computation with the resulting list of type [Int]. But for
demonstration, I made a program that just prints out the list:


import IO; import Random

minValue = 0::Int
maxValue = 1000::Int

normalize a | a < minValue = minValue
   | a > maxValue = maxValue
   | otherwise = a



normalize = min maxValue . max minValue



modify a = do
 offset <- randomRIO(-100::Int, 100)
 return(normalize(a + offset))



Stay away from IO whereever possible, use randomR instead.
Say
  map normalize (zipWith (+) (randomRs (-100::Int, 100)) x)

http://haskell.org/haskellwiki/Humor/Erlkönig
http://haskell.org/haskellwiki/Things_to_avoid#Separate_IO_and_data_processing___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: [Haskell] Re: ANN: Haddock version 2.1.0

2008-05-08 Thread Simon Marlow

David Waern wrote:

2008/5/2 Claus Reinke <[EMAIL PROTECTED]>:

2008/5/2 Simon Marlow <[EMAIL PROTECTED]>:


David Waern wrote:


No it doesn't, but it's on the TODO list. It needs a fix in GHC.

By the way, I'm going to experiment with doing the parsing of comments
on the Haddock side instead of in GHC.
If that works out, we won't have to fix these things in GHC anymore.


 Sounds great - along the lines that we discussed on cvs-ghc a while

back?

Yes, something along the lines of separately parsing the comments and
recording their source locations, and then
trying to match them with the source locations of the AST nodes.


 yay!-) i hope that the haddock-independent part (parsing, preserving,
 and accessing comments) becomes part of the GHC API in a form that would
fix trac ticket #1886, then we could finally start writing (ghc) haskell
source-to-source transformations without losing pragmas or comments!
 losing layout would still be a pain, but that could be dealt with
 later - at least the code would remain functional under some
 form of (pretty . id . parse).


Hmm. When it comes Haddock, things are simpler than in a refactoring
situation, since we don't need to know exactly where the comments
appear in the concrete syntax. The original Haddock parser is very
liberal in where you can place comments. For example, it doesn't
matter if you place a comment before or after a comma in a record
field list, it is still attached to the previous (or next, depending
on the type of comment) field. I need to take another look at the
grammar to confirm that this is true in general, though. But anyway,
my plan was to do this entirely in Haddock, not do the "preserving"
part that you mention, and not do anything to GHC.


So basically you want to run a lexer over the source again to collect all 
the comments?  You really want to use GHC's lexer, because otherwise you 
have to write another lexer.  So a flag to GHC's lexer that says whether it 
should return comments or not seems like a reasonable way to go.  But if 
you're doing that, you might as well have the parser collect all the 
comments off to the side during parsing, to avoid having to lex the file 
twice, right?


Cheers,
Simon

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


Re: [Haskell-cafe] Random numbers / monads - beginner question

2008-05-08 Thread Brent Yorgey
2008/5/8 Thomas Dinsdale-Young <[EMAIL PROTECTED]>:

> Madoc wrote:
>
> Given a list of numbers, I want to modify each of those numbers by adding a
>
> random offset. However, each such modified number shall stay within certain
>
> bounds, given by the integers minValue and maxValue. After that, I want to
> continue computation with the resulting list of type [Int].
>
>
> Personally, I'd do something like this, isolate the IO code outside the
> algorithm to keep the algorithm pure:
>
>
> modify' :: Int -> Int -> Int
> modify' offset a =  normalize (a + offset)
>
> generateInfiniteListOfRandomNumbers :: IO [Int]
> -- implementation left as an exercise
>
> main = do
>   randomNumbers <- generateInfiniteListOfRandomNumbers
>   print $ zipWith modify' randomNumbers [0, 200, 400, 600, 800, 1000]
>
> I may be wrong, but generateInfiniteListOfRandomNumbers won't terminate
> and I think it has to before the next IO action occurs.  (Laziness is great,
> but I don't think you can really do lazy IO like that.)
>

Sure it will.  You're right that you cannot do lazy IO like this, but no
lazy IO needs to happen here.  The key is that an IO action does not have to
be performed in order to generate each element of the list -- one IO action
is performed at the beginning to produce a random generator, and then this
generator is used (functionally and purely) to produce a lazy infinite list
of pseudorandom numbers.  For example see the 'newStdGen' and 'randoms'
functions from System.Random.

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


Re: [Haskell-cafe] Random numbers / monads - beginner question

2008-05-08 Thread Thomas Dinsdale-Young
 Madoc wrote:

Given a list of numbers, I want to modify each of those numbers by adding a
random offset. However, each such modified number shall stay within certain
bounds, given by the integers minValue and maxValue. After that, I want to
continue computation with the resulting list of type [Int].


Personally, I'd do something like this, isolate the IO code outside the
algorithm to keep the algorithm pure:


modify' :: Int -> Int -> Int
modify' offset a =  normalize (a + offset)

generateInfiniteListOfRandomNumbers :: IO [Int]
-- implementation left as an exercise

main = do
  randomNumbers <- generateInfiniteListOfRandomNumbers
  print $ zipWith modify' randomNumbers [0, 200, 400, 600, 800, 1000]

I may be wrong, but generateInfiniteListOfRandomNumbers won't terminate and
I think it has to before the next IO action occurs.  (Laziness is great, but
I don't think you can really do lazy IO like that.)

Instead of map :: (a -> b) -> [a] -> [b], I think you are looking for mapM
:: Monad m => (a -> m b) -> [a] -> m [b].
* *
* *Hope this helps,
Thomas

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


Re: [Haskell-cafe] Induction (help!)

2008-05-08 Thread Brent Yorgey
On Wed, May 7, 2008 at 8:01 PM, PR Stanley <[EMAIL PROTECTED]> wrote:

> So, when you apply the function to the first element in the set - e.g. Zero
> or Nil in the case of lists - you're actually testing to see the function
> works. Then in the inductive step you base everything on the assumption that
> p holds for some n and of course if that's true then p must hold for Succ n
> but you have to prove this by taking Succ from n and thus going bakc to its
> predecessor which is also the hypothesis p(n).
> So, to reiterate
> assumption: if hypothesis then conclusion
>if p(n) then p(Succ n)
> proof of assumption if p(Succ n) = Succ(p(n)) then we've won. If pn+1) =
> p(n) + p(1) then we have liftoff!
> I'm not going to go any further in case I'm once again on the wrong track.
> Cheers
> Paul
>

You've got the right idea.  I should point out that it doesn't make sense to
say p(Succ n) = Succ(p(n)),  p(x) represents some statement that is either
true or false, so it doesn't make sense to say Succ(p(n)).  But I think you
are on the right track.

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


Re: [Haskell-cafe] help in tree folding

2008-05-08 Thread Brent Yorgey
On Wed, May 7, 2008 at 6:28 AM, patrik osgnach <[EMAIL PROTECTED]>
wrote:

> Daniel Fischer ha scritto:
>
>  Am Dienstag, 6. Mai 2008 22:40 schrieb patrik osgnach:
>>
>>> Brent Yorgey ha scritto:
>>>
 On Tue, May 6, 2008 at 8:20 AM, patrik osgnach <
 [EMAIL PROTECTED]>

 wrote:

> Hi. I'm learning haskell but i'm stuck on a generic tree folding
> exercise. i must write a function of this type
> treefoldr::(Eq a,Show a)=>(a->b->c)->c->(c->b->b)->b->Tree a->c
> Tree has type
> data (Eq a,Show a)=>Tree a=Void | Node a [Tree a] deriving (Eq,Show)
> as an example treefoldr (:) [] (++) [] (Node '+' [Node '*' [Node 'x'
> [],
> Node 'y' []], Node 'z' []])
> must return "+∗xyz"
> any help?
> (sorry for my bad english)
>
 Having a (Tree a) parameter, where Tree is defined as an algebraic data
 type, also immediately suggests that you should do some pattern-matching
 to break treefoldr down into cases:

 treefoldr f y g z Void = ?
 treefoldr f y g z (Node x t) = ?

 -Brent

>>> so far i have tried
>>> treefoldr f x g y Void = x
>>>
>>
>> Yes, nothing else could be done.
>>
>>  treefoldr f x g y (Node a []) = f a y
>>>
>>
>> Not bad. But actually there's no need to treat nodes with and without
>> children differently.
>> Let's see:
>>
>> treefoldr f x g y (Node v ts)
>>
>> should have type c, and it should use v. We have
>> f :: a -> b -> c
>> x :: c
>> g :: c -> b -> b
>> y :: b
>> v :: a.
>>
>> The only thing which produces a value of type c using a value of type a is
>> f, so we must have
>>
>> treefoldr f x g y (Node v ts) = f v someExpressionUsing'ts'
>>
>> where
>>
>> someExpressionUsing'ts' :: b.
>>
>> The only thing we have which produces a value of type b is g, so
>> someExpressionUsing'ts' must ultimately be g something somethingElse.
>> Now take a look at the code and type of foldr, that might give you the
>> idea.
>>
>> Cheers,
>> Daniel
>>
>>
>>  treefoldr f x g y (Node a (t:ts)) = treefoldr f x g (g (treefoldr f x g
>>> y t) y) (Node a ts)
>>> but it is incorrect. i can't figure out how to build the recursive call
>>> thanks for the answer
>>> Patrik
>>>
>>
>>
>>  thanks for the tip.
> so, if i have understood correctly i have to wirite something like:
> treefoldr f x g y (Node a ts) = f a (g (treefoldr f x g y (head ts)) (g
> (treefoldr f x g y (head (tail ts)) (g ...
> it looks like a list foldr so...
> treefoldr f x g y Void = x
> treefoldr f x g y (Node a ts) = f a (foldr (g) y (map (treefoldr f x g y)
> ts))
> it seems to work. i'm not yet sure it is correct but is better than nothing
> thanks to you all. now i will try to write a treefoldl
>


If it typechecks and you have used all the parameters, then it is probably
correct! =)  That may sound trite, but it is often true.

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


Re: [Haskell-cafe] Random numbers / monads - beginner question

2008-05-08 Thread Claude Heiland-Allen

Madoc wrote:

Given a list of numbers, I want to modify each of those numbers by adding a
random offset. However, each such modified number shall stay within certain
bounds, given by the integers minValue and maxValue. After that, I want to
continue computation with the resulting list of type [Int].


Personally, I'd do something like this, isolate the IO code outside the 
algorithm to keep the algorithm pure:



modify' :: Int -> Int -> Int
modify' offset a =  normalize (a + offset)

generateInfiniteListOfRandomNumbers :: IO [Int]
-- implementation left as an exercise

main = do
  randomNumbers <- generateInfiniteListOfRandomNumbers
  print $ zipWith modify' randomNumbers [0, 200, 400, 600, 800, 1000]


hope this helps,


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


[Haskell-cafe] Random numbers / monads - beginner question

2008-05-08 Thread Madoc

Hello,


I am just learning Haskell. Now, I encountered something that I cannot solve
by myself. Your advice will be greatly appreciated.


Given a list of numbers, I want to modify each of those numbers by adding a
random offset. However, each such modified number shall stay within certain
bounds, given by the integers minValue and maxValue. After that, I want to
continue computation with the resulting list of type [Int]. But for
demonstration, I made a program that just prints out the list:


import IO; import Random

minValue = 0::Int
maxValue = 1000::Int

normalize a | a < minValue = minValue
| a > maxValue = maxValue
| otherwise = a

modify a = do
  offset <- randomRIO(-100::Int, 100)
  return(normalize(a + offset))

main = putStrLn $ show $ map (modify) [0, 200, 400, 600, 800, 1000]


This program will not compile. GHC complains:


test.hs:14:18:
No instance for (Show (IO Int))
  arising from a use of `show' at test.hs:14:18-21
Possible fix: add an instance declaration for (Show (IO Int))
In the first argument of `($)', namely `show'
In the second argument of `($)', namely
`show $ map (modify) [0, 200, 400, 600, ]'
In the expression:
  putStrLn $ show $ map (modify) [0, 200, 400, 600, ]


I understand that the result of the modify function is not an Int, as I
would like to have it, but instead IO Int, and that cannot be applied to
show. (I also did not quite understand why I need those brackets around the
return value of the modify value. It won't compile if I leave them out, but
I can accept that for now.)


I also figured out how to generate a modified list of type [IO Int] and of
type IO [Int]. However, I could not find out how to completely get rid of
the IO monad and just get a mofied list of type [Int], which is what I
really want.


Please, do You have any advice for me? I tried for some hours, and now I am
really angry at that IO monad that sticks to my pretty integers like glue!


Also, any comment on the programming style and how I could achive my goals
easier would be appreciated. (I left out comments and function types for the
sake of brevity.)


Thanks a lot in advance.

Madoc.
-- 
View this message in context: 
http://www.nabble.com/Random-numbers---monads---beginner-question-tp17124380p17124380.html
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] I am new to haskell

2008-05-08 Thread Ambrish Bhargava
Thanks for this list.

On Thu, May 8, 2008 at 12:29 PM, Benjamin L. Russell <[EMAIL PROTECTED]>
wrote:

> One hint that is not (at least to my knowledge) listed on haskell.org is
> that, according to at least one user (see "The Programmers' Stone » Blog
> Archive » A First Haskell Experience" at
> http://the-programmers-stone.com/2008/03/04/a-first-haskell-experience/),
> the online tutorials can "confuse more than they illuminate."
>
> Personally, I would recommend starting with one of the available books
> (see "Books - HaskellWiki" at http://haskell.org/haskellwiki/Books),
> instead.  In particular, I would recommend one of the following titles:
>
> * Paul Hudak: The Haskell School of Expression: Learning Functional
> Programming through Multimedia, Cambridge University Press, New York, 2000,
> 416 pp, 15 line diagrams, 75 exercises, Paperback $29.95, ISBN 0521644089,
> Hardback $74.95, ISBN 0521643384.  (See http://www.haskell.org/soe/.)
>  - This book uses multimedia examples to motivate learning Haskell, and is
> extremely interesting to read.  The one drawback I discovered was that some
> of the exercises assume trigonometry, which I had learned long ago but
> forgotten by the time I started reading this book.  In my opinion, this book
> is to Haskell as SICP is to Scheme (i.e., it is the authoritative textbook
> on this subject).
>
> * Kees Doets and Jan van Eijck: The Haskell Road to Logic, Maths and
> Programming, King's College Publications, London, 2004, 14.00 pounds or
> $25.00, ISBN 0-9543006-9-6.  (See 
> http://homepages.cwi.nl/~jve/HR/
> .)
>  - While this book approaches Haskell from a proof-oriented, mathematical
> perspective guided toward proving program correctness, it assumes only
> elementary mathematics and is very easy to approach.  Personally, I found it
> much easier to follow than any of the existing online tutorials.
>
> Another tip is to write your own version of Towers of Hanoi (see
> http://en.wikipedia.org/wiki/Tower_of_Hanoi) in Haskell.  Writing your own
> original programs is usually a much quicker road to mastering a programming
> language than just reading books, because it forces you to think in the
> target programming language.
>
> Benjamin L. Russell
>
> --- On Thu, 5/8/08, Ambrish Bhargava <[EMAIL PROTECTED]> wrote:
>
> > From: Ambrish Bhargava <[EMAIL PROTECTED]>
> > Subject: [Haskell-cafe] I am new to haskell
> > To: haskell-cafe@haskell.org
> > Date: Thursday, May 8, 2008, 1:37 PM
> > Hi All,
> >
> > I am new to Haskell. Can anyone guide me how can I start on
> > it (Like getting
> > binaries, some tutorials)?
> >
> > Thanks in advance.
> >
> > --
> > Regards,
> > Ambrish
> > Bhargava___
> > Haskell-Cafe mailing list
> > Haskell-Cafe@haskell.org
> > http://www.haskell.org/mailman/listinfo/haskell-cafe
>



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


Re: [Haskell-cafe] Using Template Haskell to make type-safe database access

2008-05-08 Thread Wouter Swierstra

Hi Mads,


Not only pictures, but also code can say more than a thousands words.
Therefore, I have been implementing a proof of concept. The code is
attached in two files.


Nice! I have to admit, it's much nicer than I expected it to be. Just  
out of curiousity, what happens when you write:


selectTupleList :: Connection -> IO [Integer]

instead of

selectTupleList :: Connection -> IO [(Integer, String, String)]

What kind of error message do you get? More specifically, is this  
error caught statically or dynamically.


The only other limitation I can think of, would be in the situation  
where you don't have compile-time access to the database, e.g.  
developing software for a client with a database that can only be  
accessed from their intranet. I have no idea how much of a limitation  
that is.



ok, there is some noise. But at the end of line three it says "Unknown
column 'duser_id'". Also with a little more work I could properly
improve the output.


The message is a bit verbose, but if you ignore the noise, it gives  
pretty good feedback about what's wrong. Good.



Perhaps I should explain my own thoughts on the subject a bit better.
I got interested in this problem because I think it makes a nice
example of dependent types "in the real world" - you really want to


But won't you end up implementing all the functionality of an SQL
parser? While possible, it does seem like a huge job. With a TH  
solution

you will safe a lot of work.


Yes - but parsing the result of an SQL describe statement is pretty  
easy.



A library that
will be a lot more complex to learn than what I am proposing (assuming
the developer already knows SQL).


Hmm. This is a rather sticky point. One might also argue that Haskell  
developers have to learn SQL to use the solution you propose. I'm not  
particularly convinced. Both approaches have their merits I think.


Anyhow - nice work! Have you asked Bjorn Bringert what he thinks? He's  
a really clever and approachable guy - and he knows a lot more about  
interfacing with databases than I do.


Kind regards,

  Wouter


This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.

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


Re : [Haskell-cafe] I am new to haskell

2008-05-08 Thread minh thu
Hi,

Personnaly, I started to learn Haskell with A Gentle Introduction and
(from what I recall) really enjoyed it.

I find The Haskell School of Expression a bit problematic because it
interleaves information about the language with (although nice) large
running-through-all-the-chapter examples.

Anyway, welcome !
Thu

2008/5/8, Benjamin L. Russell <[EMAIL PROTECTED]>:
> One hint that is not (at least to my knowledge) listed on haskell.org is
> that, according to at least one user (see "The Programmers' Stone » Blog
> Archive » A First Haskell Experience" at
> http://the-programmers-stone.com/2008/03/04/a-first-haskell-experience/),
> the online tutorials can "confuse more than they illuminate."
>
> Personally, I would recommend starting with one of the available books (see
> "Books - HaskellWiki" at http://haskell.org/haskellwiki/Books), instead.  In
> particular, I would recommend one of the following titles:
>
> * Paul Hudak: The Haskell School of Expression: Learning Functional
> Programming through Multimedia, Cambridge University Press, New York, 2000,
> 416 pp, 15 line diagrams, 75 exercises, Paperback $29.95, ISBN 0521644089,
> Hardback $74.95, ISBN 0521643384.  (See http://www.haskell.org/soe/.)
>   - This book uses multimedia examples to motivate learning Haskell, and is
> extremely interesting to read.  The one drawback I discovered was that some
> of the exercises assume trigonometry, which I had learned long ago but
> forgotten by the time I started reading this book.  In my opinion, this book
> is to Haskell as SICP is to Scheme (i.e., it is the authoritative textbook
> on this subject).
>
> * Kees Doets and Jan van Eijck: The Haskell Road to Logic, Maths and
> Programming, King's College Publications, London, 2004, 14.00 pounds or
> $25.00, ISBN 0-9543006-9-6.  (See http://homepages.cwi.nl/~jve/HR/.)
>   - While this book approaches Haskell from a proof-oriented, mathematical
> perspective guided toward proving program correctness, it assumes only
> elementary mathematics and is very easy to approach.  Personally, I found it
> much easier to follow than any of the existing online tutorials.
>
> Another tip is to write your own version of Towers of Hanoi (see
> http://en.wikipedia.org/wiki/Tower_of_Hanoi) in Haskell.  Writing your own
> original programs is usually a much quicker road to mastering a programming
> language than just reading books, because it forces you to think in the
> target programming language.
>
> Benjamin L. Russell
>
> --- On Thu, 5/8/08, Ambrish Bhargava <[EMAIL PROTECTED]> wrote:
>
> > From: Ambrish Bhargava <[EMAIL PROTECTED]>
> > Subject: [Haskell-cafe] I am new to haskell
> > To: haskell-cafe@haskell.org
> > Date: Thursday, May 8, 2008, 1:37 PM
> > Hi All,
> >
> > I am new to Haskell. Can anyone guide me how can I start on
> > it (Like getting
> > binaries, some tutorials)?
> >
> > Thanks in advance.
> >
> > --
> > Regards,
> > Ambrish
> > Bhargava___
> > 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 mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] The Monad.Reader (11) - Call for Copy

2008-05-08 Thread Wouter Swierstra


On 7 May 2008, at 19:56, Andrew Coppin wrote:


Wouter Swierstra wrote:
Please consider writing something for the next issue of The  
Monad.Reader.


You know, I'm actually tempted to do just that...


Please do! We've had lots of excellent articles written by people who  
were just learning Haskell. Sometimes a beginner's perspective can be  
quite refreshing. Feel free to contact me personally if you have any  
questions.


All the best,

  Wouter

This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.

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