[Haskell-beginners] Is Cons in the Haskell Module Library
Brandon Allbery
allbery.b at gmail.com
Sun Dec 22 17:51:13 UTC 2013
On Sun, Dec 22, 2013 at 12:23 PM, Patrick Lynch <kmandpjlynch at verizon.net>wrote:
> Good morning,
> I'm going through Graham Hutton's link on Category Theory [and yes I
> understand that you needn't study CT in order to use Haskell] and he uses
> Cons.
> I realize that Cons may be a synonym for ':'.
> But can someone tell me how to search the Haskell Library to find the
> module containing Cons?
>
The usual point of Cons is that it's instructive to reconstruct the list
type from first principles. You would never do this in a real program,
since it's exactly the same as the built-in list type --- except that it
doesn't come with all the predefined list stuff, so it's easier for you to
build it yourself without interfering with (or being interfered with by!)
the standard library. It also doesn't come with the convenient syntactic
sugar. And even if for some reason you did need to restrict lists that way
in a real program, you would probably use a newtype instead so that you can
still use the standard list operations and syntax after unwrapping.
data List a = Nil | Cons a (List a)
data [] a = [] | (:) a ([] a) -- the builtin list type, for
comparison
--
brandon s allbery kf8nh sine nomine associates
allbery.b at gmail.com ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20131222/44e44737/attachment.html>
More information about the Beginners
mailing list