Skip to content

Instantly share code, notes, and snippets.

@wclr
Forked from dlants/generic-deriving.purs
Created April 19, 2021 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wclr/3cc2314da5902610c6e836317d9b64dc to your computer and use it in GitHub Desktop.
Save wclr/3cc2314da5902610c6e836317d9b64dc to your computer and use it in GitHub Desktop.
Generic deriving with purescript
-- an example of how to derive a show instance for a Maybe type
-- not totally sure why `derive instance showMyMaybe :: (Show a) => Show (MyMaybe a)` errors with...
-- error: CannotDerive :
-- Cannot derive a type class instance for Data.Show.Show (MyMaybe a) since instances of this type class are not derivable.
module Main where
import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow)
data MyMaybe a
= Just a
| Nothing
derive instance genericMyMaybe :: Generic (MyMaybe a) _
instance showMyMaybe :: (Show a) => Show (MyMaybe a) where show = genericShow
main :: forall e. Eff (console :: CONSOLE | e) Unit
main = do
log $ show $ Just "hello, deriving!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment