YAHT Question about Exercise 4.8

From the previous examples, I was thinking something like Cons 'a' 'b' 'c' would create a list ['a','b','c'] but it gave me errors... help please,
Hi, I was trying to use the solution given, but I don't know how to use it... How do I create something that is of type List? data List a = Nil | Cons a (List a) thanks. -- View this message in context: http://www.nabble.com/YAHT-Question-about-Exercise-4.8-tp24655087p24655087.h... Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

Cons 'a' (Cons 'b' (Cons 'c' Nil)) equivalent to 'a' : ('b' : ('c' : [])) using Haskell's normal list type. -Ross On Jul 25, 2009, at 2:55 AM, Futari wrote:
Hi, I was trying to use the solution given, but I don't know how to use it... How do I create something that is of type List?
data List a = Nil | Cons a (List a)
From the previous examples, I was thinking something like Cons 'a' 'b' 'c' would create a list ['a','b','c'] but it gave me errors... help please, thanks.
-- View this message in context: http://www.nabble.com/YAHT-Question-about-Exercise-4.8-tp24655087p24655087.h... 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

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 On Sat, Jul 25, 2009 at 2:55 AM, Futari wrote:
Hi, I was trying to use the solution given, but I don't know how to use it... How do I create something that is of type List?
data List a = Nil | Cons a (List a)
From the previous examples, I was thinking something like Cons 'a' 'b' 'c' would create a list ['a','b','c'] but it gave me errors... help please, thanks.
Think about what Cons 'a' 'b' 'c' means. You're trying to pass Cons three arguments - Cons x y z. But your definition of Cons says it takes *2* arguments. Clearly there's a contradiction here. Now, your first argument to Cons can be anything; in this case, it's 'a', which is a Char. So the second argument must be List a, which has exactly two alternatives: either Nil, or another Cons... eventually we must bottom out at Nil. The simplest example would be Cons 'a' Nil, which evaluates to Cons 'a' Nil it :: List Char But we could substitute in another Cons, for Cons 'a' (Cons 'b' ...?). We could terminate the list here with a Nil, but we'll go one more deep: Cons 'a' (Cons 'b' (Cons 'c' Nil)), which will again evaluate correctly to it :: List Char - -- gwern -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEAREKAAYFAkpqrlIACgkQvpDo5Pfl1oJi7QCgiRXILcu8P4ka76BE7tjXeekT 5ycAn3pno8Gh6YGSboV/039gbIfpoYHS =4V5w -----END PGP SIGNATURE-----

Hello Futari, Saturday, July 25, 2009, 10:55:34 AM, you wrote:
data List a = Nil | Cons a (List a)
this definition says that Nil is a valid list. also it says that Cons 'a' (xxx) is a valid list as long as xxx is a valid list, so Cons 'c' (Nil) would be a valid list too. continuing to use second rule we may get the following: Cons 'a' (Cons 'b' (Cons 'c' (Nil))) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com
participants (4)
-
Bulat Ziganshin
-
Futari
-
Gwern Branwen
-
Ross Mellgren