-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Functors for the "Generic Extensions to Type Operators" #3
Comments
For 14.3c: you probably want something like
|
Or maybe implementing
|
Oh that's really nice. I wonder what the usecase for such a functor could be? Is the list functor more general or length 2 vector functors. |
It's the
|
@CMCDragonkai In this case (the products) we have three functor instances (ignoring any thing "inside" the
In a list or (properly) a vector we'd have two:
If "more general" means "can be correctly applied to more things" then the former is more general because we can always choose |
How about this definition for 14.[13]e -- | Sum type with two constructors (l and r prefix)
data Sum a b t = L (a t) | R (b t) deriving (Eq, Show)
instance (PolyFunc tau1, PolyFunc tau2) -- 14.1e, premises
=> PolyFunc (Sum tau1 tau2)
where pfmap f e
= case e of -- 14.3e. Confusing part is
L x1 -> L (pfmap f x1) -- that the target type is
R x2 -> R (pfmap f x2) -- again the same sum type I got distracted and wrote all rules in a file here: |
@jberthold I think I agree with the revision @thsutton made earlier to use So, I guess type Sum a b t = Either (a t) (b t) Also, I added a comment to your gist - basically I think |
It's perhaps more common (and a little nicer) in Haskell land to use infix operators |
Was I on crack yesterday? None of the synonym stuff works today. :-/ |
@mjhopkins True, infix constructors would be closer to the book as well. However, note that I am not switching on any Haskell extensions. :-) EDIT: by "note" I mean "go on a network that does allow you to see..." :-S |
I sometimes find it easier to understand if I relate the PFPL to equivalent constructs in Haskell.
Regarding today's meeting for page 123. We have a 5 polynomial type operators. Here are some equivalences I've found:
For 14.3.a:
For 14.3b:
There used to be a
Data.Unit
in category-extras package, but it was removed.For 14.3c:
Unknown. Originally I thought it was a tuple. But it isn't. Also this is close
data Pair a = Pair a a
but it doesn't exactly match{t.tau1 * tau2}
, it would be more like{t.t * t}
.For 14.3d:
Could be
Data.Void
, but it's not an instance of the Functor type class. Also I couldn't make it an instance of Functor because the kind is*
and Functor needs a kind of* -> *
.The closest thing to the same behaviour is...
For 14.3e:
Not sure, could it be the
Either
functor?The text was updated successfully, but these errors were encountered: