[Haskell-cafe] data type declaration
Vo Minh Thu
noteed at gmail.com
Sun Jul 25 10:56:41 EDT 2010
2010/7/25 Andrew Coppin <andrewcoppin at btinternet.com>:
> Patrick Browne wrote:
>> Thanks for your detailed feedback, it is a great help.
> Well, I like to be helpful.
>> I appreciate that the code does not do anything useful, nor is it an
>> appropriate way to write Haskell, but it does help me
>> understand language constructs.
> Personally, I find it easier to understand things when they do something
> meaningful, but sure.
>> I am studying the Haskell type class system as part of a language
>> comparison. I am trying to exercise and understand the constructs rather
>> than develop a meaningful application.
> The best way to understand Haskell is... to completely forget everything you
> already know, and start again from scratch. ;-) Still, I gather that's not
> the point of this particular exercise.
> Since you're interested in comparisons... A method is simply a way of giving
> the same name to several different functions, and have the compiler pick the
> correct one based on the argument types.
Actually in Haskell, the choice of the correct definition is not only
based on the argument types. It could be based on the result type:
class C a where
f :: a
g :: a -> Int
h :: String -> a
An example of the 'h' case is simply the 'read' function:
Prelude> :t read
read :: (Read a) => String -> a
Prelude> read "1" :: Int
Prelude> read "1" :: Double
Note that usually, the type annotation is not needed because the
compiler has enough information from the context to infer it.
More information about the Haskell-Cafe