Skip to content
This repository was archived by the owner on Mar 25, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"purescript-enums": "^4.0.0",
"purescript-foldable-traversable": "^4.0.0",
"purescript-maybe": "^4.0.0",
"purescript-either": "^4.0.0",
"purescript-newtype": "^3.0.0",
"purescript-prelude": "^4.0.0"
},
Expand Down
9 changes: 9 additions & 0 deletions src/Data/Generic/Rep.purs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Data.Generic.Rep
) where

import Data.Maybe (Maybe(..))
import Data.Either (Either(..))

-- | A representation for types with no constructors.
data NoConstructors
Expand Down Expand Up @@ -46,3 +47,11 @@ instance genericMaybe
from Nothing = Inl (Constructor NoArguments)
from (Just a) = Inr (Constructor (Argument a))

instance genericEither
:: Generic (Either a b) (Sum (Constructor "Left" (Argument a))
(Constructor "Right" (Argument b))) where
to (Inl (Constructor (Argument a))) = Left a
to (Inr (Constructor (Argument b))) = Right b

from (Left a) = Inl (Constructor (Argument a))
from (Right b) = Inr (Constructor (Argument b))