George312
George312

Reputation: 27

How to sum a (float,float) type elements in Haskell?

Here is my code
Now it works with Float -> Float -> Float but i can't make it work with my defined "Complex" type.

I would like to make it look and work like this.

   add :: Complex -> Float


I think it's like chaning only a few words but i can't figure it out. Thanks for your patience.

Here is my code

type Complex = (Float,Float)

add :: Float -> Float -> Float
add a b = a+b


xor :: Float -> Float -> Float
xor a b = a*b

Upvotes: 0

Views: 659

Answers (1)

bwroga
bwroga

Reputation: 5449

If you defined add like this:

add :: Float -> Float -> Float
add a b = a+b

You could apply add to Complex objects like this:

uncurry add (2.0, 3.0)

uncurry "converts" a function of type (a -> b -> c) to a function of type ((a, b) -> c)

Upvotes: 1

Related Questions