Skip to content

Instantly share code, notes, and snippets.

@leobm
Forked from dlants/generic-deriving.purs
Created December 14, 2020 13:41
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 leobm/bd7000e4a8202795b95292c817764268 to your computer and use it in GitHub Desktop.
Save leobm/bd7000e4a8202795b95292c817764268 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