Reputation: 73
I'm starting my adventure with Haskell language and I need a little help. How should I define swap function which is declared:
swap :: (Int, Char) -> (Char, Int)
Probably it's very easy, but I have problem with that.
Upvotes: 2
Views: 8317
Reputation: 364
You can also be more general with:
swap :: (a, b) -> (b, a)
swap (x, y) = (y, x)
This works for all types, not just for Int
and Char
.
Upvotes: 9
Reputation: 36375
swap :: (Int, Char) -> (Char, Int)
swap (a, b) = (b, a)
You might want to read up on pattern matching in Haskell.
Upvotes: 7