
That is correct. You can think of type parameters as being curried and
applied the same way as function parameters. Since application is strictly
left to right, and we have no type-level flip function (barring newtype),
getting your type down to the single parameter allowed in a Functor
instance can only ever mean using the rightmost parameter in the type's
definition. This is just a semantic limitation of how Haskell types are
expressed.
On Mar 3, 2018 7:56 PM, "Hilco Wijbenga"
On Sat, Mar 3, 2018 at 6:41 PM, Francesco Ariis
wrote: 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).
I believe I am talking about "failure" the type parameter.
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
Yes, indeed. But that's what I meant with 'now "a" has a different meaning'. I understand that to the compiler there is no practical difference between Result a b and Result b a ... but there is to me. :-)
So am I to understand then that to be able to do the kind of "fmap" I want (i.e. one that affects the "success" value), I _have to_ make sure that I use "Result failure success" (and not "Result success failure")? _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners