Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd Inject instance for tuples #100
Conversation
This comment has been minimized.
This comment has been minimized.
|
What I'd suggest doing here is to first define an data R2 a b = R2 { _1 :: a, _2 :: b }
deriving (Generic, Inject, Interpret)... and then defining the instance (Inject a, Inject b) => Inject (a, b) where
injectWith = fmap (contraMap adapt) injectWith
where
adapt (_1, _2) = R2 {..})The advantage of this approach is that it's easy to scale out to larger tuple sizes The other advantage is that you can also export the |
This comment has been minimized.
This comment has been minimized.
|
Also, while you're doing this, you can also define a matching |
This comment has been minimized.
This comment has been minimized.
You are right, this looks much better. I'll update the pull request.
Will do. |
bosu
force-pushed the
bosu:tuple-it
branch
from
210ce1f
to
e937d7c
Aug 20, 2017
This comment has been minimized.
This comment has been minimized.
|
Rebased and updated the pull request. |
Gabriel439
reviewed
Aug 20, 2017
|
It looks like the build failure is not your fault. Somehow the |
| -- | Dhall uses this type to represent (a, b) tuple. | ||
| data R2 a b = R2 { _1 :: a, _2 :: b } deriving (Show, Generic) | ||
|
|
||
| instance (Inject a, Inject b) => Inject (R2 a b) |
This comment has been minimized.
This comment has been minimized.
Gabriel439
Aug 20, 2017
Collaborator
If you add the DeriveAnyClass extension, then you can simplify this further as just:
data R2 a b = R2 { _1 :: a, _2 :: b }
deriving (Generic, Inject, Interpret, Show)
bosu
force-pushed the
bosu:tuple-it
branch
from
e937d7c
to
d13200c
Aug 21, 2017
This comment has been minimized.
This comment has been minimized.
|
Update pull request uses |
This comment has been minimized.
This comment has been minimized.
|
I'll go ahead and merge this and then fix the build failure on |
bosu commentedAug 20, 2017
(a, b)is mapped to{ _1 = a, _2 = b }