Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
You can’t perform that action at this time.