I'm a C# developer who is working through "Real World Haskell" in order to truly understand functional programming, so that when I learn F#, I'll really grok it and not just "write C# code in F#", so to speak.
Well, today I came across an example which I thought I understood 3 different times, only to then see something I missed, update my interpretation, and recurse (and curse too, believe me).
Now I believe that I do actually understand it, and I have written a detailed "English interpretation" below. Can you Haskell gurus please confirm that understanding, or point out what I have missed?
Note: The Haskell code snippet (quoted directly from the book) is defining a custom type that is meant to be isomorphic to the built in Haskell list type.
The Haskell code snippet
data List a = Cons a (List a)
| Nil
defining Show
EDIT: After some responses, I see one misunderstanding I made, but am not quite clear on the Haskell "parsing" rules that would correct that mistake. So I've included my original (incorrect) interpretation below, followed by a correction, followed by the question that still remains unclear to me.
EDIT: Here is my original (incorrect) "English interpretation" of the snippet
- I am defining a type called "List".
- The List type is parameterised. It has a single type parameter.
- There are 2 value constructors which can be used to make instances of List. One value constructor is called "Nil" and the other value constructor is called "Cons".
- If you use the "Nil" value constructor, then there are no fields.
- The "Cons" value constructor has a single type parameter.
- If you use the "Cons" value constructor, there are 2 fields which must be provided. The first required field is an ins