From 1fc1178df9091a3f3315cb4108bd8bab9b89ec67 Mon Sep 17 00:00:00 2001 From: David Smith Date: Wed, 8 May 2019 11:36:33 +0100 Subject: [PATCH] add Generic Either instance --- bower.json | 1 + src/Data/Generic/Rep.purs | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/bower.json b/bower.json index 1011636..65ef07e 100644 --- a/bower.json +++ b/bower.json @@ -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" }, diff --git a/src/Data/Generic/Rep.purs b/src/Data/Generic/Rep.purs index 92bf845..7c5c4e6 100644 --- a/src/Data/Generic/Rep.purs +++ b/src/Data/Generic/Rep.purs @@ -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 @@ -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)) \ No newline at end of file