On Fri, Oct 31, 2003 at 05:30:06PM +0550, gangadhar npk wrote:
> hi,
>   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 forgot about function arguments in its type. It should be:

square :: (Num a, Num b) => (a, b) -> (a, b)

Next time try commenting out the type signature and see if the compiler
can infer the type. Both Hugs and GHCi provide commands for inspecting
types of values.

Prelude> let square (x,y) = (x*x,y*y)
Prelude> :type square
forall a a1. (Num a1, Num a) => (a1, a) -> (a1, a)

You can use :t as a shortcut.

> thank you
> gangadhar

Best regards,
Tom

-- 
.signature: Too many levels of symbolic links
_______________________________________________
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to