Last active
April 19, 2021 15:54
-
-
Save dlants/1247c5a6ab89342560fe40075646320a to your computer and use it in GitHub Desktop.
Generic deriving with purescript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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