I want to write a function in haskell which would not mind in what order I provide it its argument, for example, I want to unify these two functions
reproduce1 :: Male -> Female -> Child
reproduce2 :: Female -> Male -> Child
by one function 'reproduce'.
You can do this using a multi-parameter type class.
{-# LANGUAGE MultiParamTypeClasses #-}
class Reproduce x y where
reproduce :: x -> y -> Child
instance Reproduce Male Female where
reproduce = reproduce1
instance Reproduce Female Male where
reproduce = reproduce2
However, I'm curious about why you would want to do this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With