
Hi everyone. I've got a few questions about the Haskell programming language. 1) what's the difference between these two code statements? I'm convinced they should be the same type T = [Char] type CurrentValue = Char My concern is that in the second one there are no brackets Anyway they are actually declarations arent'they? 2) What is Maybe String? For instance: type P = (Char, Maybe String) Is that a function which has two arguments ? 3) What is Maybe Char ? For instance : type D = ((Maybe Char) , Char) It's another function having three arguments..am I right? Thanks a lot. 777P -- moowoo9@fastmail.fm -- http://www.fastmail.fm - The professional email service

All of your questions are answered very nicely in this tutorial:
David Place Owner, Panpipes Ho! LLC http://panpipesho.com d@vidplace.com On Jul 2, 2011, at 11:37 AM, moowoo9@fastmail.fm wrote:
Hi everyone. I've got a few questions about the Haskell programming language.
1) what's the difference between these two code statements? I'm convinced they should be the same
type T = [Char] type CurrentValue = Char
My concern is that in the second one there are no brackets
Anyway they are actually declarations arent'they?
2) What is Maybe String?
For instance: type P = (Char, Maybe String)
Is that a function which has two arguments ?
3) What is Maybe Char ?
For instance : type D = ((Maybe Char) , Char)
It's another function having three arguments..am I right?
Thanks a lot. 777P
--
moowoo9@fastmail.fm
-- http://www.fastmail.fm - The professional email service
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

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]
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: findNeedle :: NeedleID -> Haystack -> Maybe Needle In that example, findNeedle would return the value: Just someneedle OR it would return Nothing if it could not be found. I encourage you to read up on the tutorial that David Place submitted for more information.
For instance: type P = (Char, Maybe String)
P in this case is a tuple or pair. That's what the parentheses are for. It means that the first field of the tuple is a Char, the second field of of the tuple can either be a string or nothing. Again, this is a type, not a value or a function.
3) What is Maybe Char ?
See above. -- Michael Xavier http://www.michaelxavier.net

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.

No. [Char] is a list, not array, of Char. That is, something like
My bad. I let my Ruby mind take over. In Ruby, the most basic list-like structure is an array, which shares some similarities with Haskell's list ( O(1) lookups not being one of them). -- Michael Xavier http://www.michaelxavier.net
participants (4)
-
David Place
-
Jared Hance
-
Michael Xavier
-
moowoo9@fastmail.fm