[prev in list] [next in list] [prev in thread] [next in thread] 

List:       haskell-beginners
Subject:    Re: [Haskell-beginners] Haskell type definitions
From:       Gesh <gesh () gesh ! uni ! cx>
Date:       2013-04-11 16:55:14
Message-ID: 5166EAF2.1000001 () gesh ! uni ! cx
[Download RAW message or body]

Also, this syntax can be used in general to specify the type of a value.
i.e. a :: (c1,c2,...,cn) => t means that the name a has type t, where
the type that t represents is constrained by all the constraints ci.
e.g. foo :: (Num a, Ord b, Eq a) => (a,b) -> (a -> b) -> (b,b)
notes that the type of foo is a function from pairs of a and b to
functions from functions from a to b to pairs of a and b. However,
the a and b previously noted are subject to the constraints that:
- a must be an instance of Num and Eq
- b must be an instance of Ord
This is useful in many cases, which include:
- Documenting the type of a function
- Coercing a literal to a specific type (e.g. 23 :: Float)
- When checking type inference, using (undefined :: a) as a parameter
   allows me to check types without having to invent some input
- When using type aliases and typeclasses, telling GHCi that your
   expression has some type will either give you a type error or clean
   up the type signature for your expression. e.g. :t "foo" is [Char],
   but :t "foo" :: String is String, so you can check whether the more
   concise type signature is also correct.

Best regards, and wishing you much enjoyment studying Haskell,
Gesh

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic