Skip to content

PureScript Type Classes

In purescript, type classes mostly work how users of Haskell would expect. However, type classes in purescript do need to be given names. This is because it transpiles into JavaScript, which needs to be able to name the entity.

Basics

This defines a typeclass for any a that converts it into a string.

class Show a where
    show :: a -> String

In order to implement this for a type:

data MyCustomType = One | Two

implement showMyCustomType :: Show MyCustomType where
    show One = "One"
    show Two = "Two"