newbie question regarding type declarations
ddarius at hotpop.com
Fri Oct 31 08:03:54 EST 2003
On Fri, 31 Oct 2003 17:30:06 +0550
"gangadhar npk" <phani at myrealbox.com> wrote:
> I am a newbie to Haskell. I am reading the tutorial by Hal Daume
> III. Regarding the function types which are an extension of lambda
> calculus, I was wondering if at all it is possible to write a type
> that would return two values as the output - something like a square
> function which would take a pair and return a pair.
> I tried this, but there are errors
> square :: (Num a, Num b) => (a ,b)
> square (x , y) = (x*x , y*y)
> How can I specify that the square functions output would be a pair ?
You don't need to provide a type signature, Haskell can figure it out.
You can use :type in a repl (e.g. Hugs, GHCi) to print out the type of
an expression. So, you can either put 'square (x,y) = (x*x,y*y)' into a
file and load it and do ':t square' or you can do something like,
:t let square (x,y) = (x*x,y*y) in square
and get ...
<fill in the blank>
Also, for future reference, if you need help with something it helps to
provide all the information you can. Things like the actual text of the
error messages, the implementation you are using, and the operating
system you are using. Basically, the more information you can provide
More information about the Haskell-Cafe