git.iko.soy/rowtype-yoga/purescript-native
on 33cfbe7 help sign in
26 lines 870 B history raw
1Type Classes
2============
4PureScript has basic support for type classes via the `class` and `instance` keywords.
6Type class instances must be of the form `String`, `Number`, `Boolean`, `[t]` or `C t1 ... tn`, and only a single type class parameter is supported.
8Type class instances are resolved based on the order in which they appeared in the source files. In particular, overlapping instances are permitted.
10Here is an example of the `Show` typeclass, with instances for Strings, Booleans and arrays::
12 class Show a where
13 show :: a -> String
15 instance showString :: Show String where
16 show s = s
18 instance showBoolean :: Show Boolean where
19 show true = "true"
20 show false = "false"
22 instance showArray :: (Show a) => Show [a] where
23 show [] = "[]"
24 show (x:xs) = show x ++ " : " ++ showArray xs
26 example = show [true, false]