
On Sat, Jul 02, 2011 at 12:00:44PM -0700, Michael Xavier wrote:
From: Michael Xavier
To: moowoo9@fastmail.fm Cc: beginners@haskell.org Date: Sat, 2 Jul 2011 12:00:44 -0700 Subject: Re: [Haskell-beginners] Understandig types I do agree you should look at the tutorial but to answer your questions, see below:
1) what's the difference between these two code statements? I'm
convinced they should be the same
type T = [Char] type CurrentValue = Char
You could think of the type keyword as aliasing an existing type to one that you name. For instance, T can now be used interchangeably with the [Char] type, like in a type declaration:
upcase :: [Char] -> [Char] can be: upcase :: T -> T
and they would mean the same thing. You do this usually for the sake of documentation, where the alias you are creating is more readable than that which it aliases.
[Char] means an array of Chars. String, for example is I believe defined as: type String = [Char]
No. [Char] is a list, not array, of Char. That is, something like data List a = Cons a (List a) | Empty
2) What is Maybe String?
Maybe String is a datatype that could be 1 of 2 things, a String or Nothing. Maybe is used a lot of the time for computations that may fail, such as looking for a needle in a haystack:
To elaborate: It is data Maybe a = Just a | Nothing in ADT form.