Skip to content
This repository was archived by the owner on Mar 25, 2021. It is now read-only.

Commit 0444c79

Browse files
LiamGoodacrepaf31
authored andcommitted
Add Generic instance for Maybe (#9)
1 parent 00f3c44 commit 0444c79

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/Data/Generic/Rep.purs

+12
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ module Data.Generic.Rep
1212
, Field(..)
1313
) where
1414

15+
import Data.Maybe (Maybe(..))
16+
1517
-- | A representation for types with no constructors.
1618
data NoConstructors
1719

@@ -43,3 +45,13 @@ newtype Field (field :: Symbol) a = Field a
4345
class Generic a rep | a -> rep where
4446
to :: rep -> a
4547
from :: a -> rep
48+
49+
instance genericMaybe
50+
:: Generic (Maybe a) (Sum (Constructor "Nothing" NoArguments)
51+
(Constructor "Just" (Argument a))) where
52+
to (Inl _) = Nothing
53+
to (Inr (Constructor (Argument a))) = Just a
54+
55+
from Nothing = Inl (Constructor NoArguments)
56+
from (Just a) = Inr (Constructor (Argument a))
57+

0 commit comments

Comments
 (0)