Re: Re[2]: [Haskell-cafe] Confused about Cyclic struture
On Sat, 2005-07-09 at 13:12 +0400, Bulat Ziganshin wrote: Hello Dinh, Friday, July 08, 2005, 9:12:22 PM, you wrote: DTTA Another question, it's said in the book that using cyclic structure (like DTTA ones = 1:ones) , the list would be represented by a fixed amount of memory. DTTA Does it mean [1,1,1..] only occupy one cell of memory ? DTTA How about in take 100 [1,1,...] ? in order to understand how Haskell datastructures uses memory, you must remember that Haskell does LAZY evaluation. Hi, I'll be a little bit pedantic here. Haskell, the language definition, does not prescribe lazy evaluation. It says that the language is non-strict. Lazy evaluation is an implementation technique which satisfies non-strict semantics, but it is not the only technique which does this. As it happens, GHC, Hugs and nhc98 all employ lazy evaluation. Note that they may still vary in subtle ways as to the precise details of evaluation order, due to program transformations that may be applied to the program during compilation. As I said in my previous mail, the degree of sharing you get within Haskell data structures is not defined in the language, it is defined (perhaps loosely) by the implementation technique. Cheers, Bernie. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Confused about Cyclic struture
Bernard Pope wrote: I'll be a little bit pedantic here. Haskell, the language definition, does not prescribe lazy evaluation. It says that the language is non-strict. Lazy evaluation is an implementation technique which satisfies non-strict semantics, but it is not the only technique which does this. This pedantry is renewed periodically. It is a pity that nobody ever writes anything about that other methods of implementation of non-strictness, nor about the languages which use those methods. I believe it might do some good to people who learn functional programming in general, and Haskell in particular. Any takers? Jerzy Karczmarczuk ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Can't explain this error
i have just encountered another type error. This program tries to print out partitions of a positive integer (i guess) parts 0 = [[]] parts x = [concat (map (y:) parts(x-y) | y-[1..(x `div` 2)]] and got this error: Expression : map (y:) parts(x-y) Term : map Type: (e-f) - [e] - [f] Does not match: a - b - c - d why do i have this error ? How to fix it ? Thanks a lot _ It's fast, it's easy and it's free. Get MSN Messenger 7.0 today! http://messenger.msn.co.uk ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Can't explain this error
On 2005-07-12 at 12:39- Dinh Tien Tuan Anh wrote: i have just encountered another type error. This program tries to print out partitions of a positive integer (i guess) parts 0 = [[]] parts x = [concat (map (y:) parts(x-y) | y-[1..(x `div` 2)]] ^ suspicious spacing! That's the same as parts x = [concat (map (y:) parts (x-y) | y-[1..(x `div` 2)]] ie you are giving map three arguments when it expects two, which is what the type error says. -- Jón Fairbairn Jon.Fairbairn at cl.cam.ac.uk ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Can't explain this error
On 12 Jul 2005, at 14:39, Dinh Tien Tuan Anh wrote: parts 0 = [[]] parts x = [concat (map (y:) parts(x-y) | y-[1..(x `div` 2)]] First of all ... there is a ) missing ... I guess the line should read parts x = [concat (map (y:) parts(x-y) ) | y-[1..(x `div` 2)]] ? -- Andy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Can't explain this error
oh damn, thank you From: Jon Fairbairn [EMAIL PROTECTED] To: Dinh Tien Tuan Anh [EMAIL PROTECTED] CC: [EMAIL PROTECTED], haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] Can't explain this error Date: Tue, 12 Jul 2005 14:08:00 +0100 On 2005-07-12 at 12:39- Dinh Tien Tuan Anh wrote: i have just encountered another type error. This program tries to print out partitions of a positive integer (i guess) parts 0 = [[]] parts x = [concat (map (y:) parts(x-y) | y-[1..(x `div` 2)]] ^ suspicious spacing! That's the same as parts x = [concat (map (y:) parts (x-y) | y-[1..(x `div` 2)]] ie you are giving map three arguments when it expects two, which is what the type error says. -- Jón Fairbairn Jon.Fairbairn at cl.cam.ac.uk _ Winks nudges are here - download MSN Messenger 7.0 today! http://messenger.msn.co.uk ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] a simple function
Anyone please tell me what is wrong with the function: isEmpty ::[a]-Bool isEmpty xs | xs == [] = True |otherwise =False When I tried to load it into the interpreter,it says the following: Could not deduce (Eq a) from the context () arising from use of `==' at mylab2.hs:16 Probable fix: Add (Eq a) to the type signature(s) for `isEmpty' In a pattern guard for the definition of `isEmpty': xs == [] In the definition of `isEmpty': isEmpty xs | xs == [] = True -- X.W.D ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] a simple function
On Tue, 12 Jul 2005, wenduan wrote: Anyone please tell me what is wrong with the function: isEmpty ::[a]-Bool isEmpty xs | xs == [] = True |otherwise =False When I tried to load it into the interpreter,it says the following: Could not deduce (Eq a) from the context () arising from use of `==' at mylab2.hs:16 It means that the comparison with (==) only works for types of the Eq class. This also applies to comparison with the empty list because there are different types of empty lists. Thus you have to write isEmpty :: Eq a = [a] - Bool But it is a bad solution. Better is isEmpty [] = True isEmpty _ = False or even better: Use the standard function 'null'. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe