[Haskell-beginners] Functor instance
Francesco Ariis
fa-ml at ariis.it
Sun Mar 4 02:41:39 UTC 2018
On Sat, Mar 03, 2018 at 06:31:47PM -0800, Hilco Wijbenga wrote:
> In any case, _when_ I flip "success" and "failure" the Functor
> instance no longer compiles. Which probably makes sense because I did
> not tell the compiler to interpret "Result failure" as "Result *
> failure"?
I wonder if you are talking about failure (type parameter) or
Failure (data constructor). This instance obviously work
instance Functor (Result success) where
fmap f (Success value) = Success (f value)
fmap _ (Failure error) = Failure error
Flipping in `data` of course means you are to flip one of:
a) instance or b) data constructor, e.g.:
instance Functor (Result success) where
fmap f (Failure error) = Failure (f error)
fmap _ (Success value) = Success value
More information about the Beginners
mailing list