git.iko.soy/rowtype-yoga/purescript-native
on 64bd2db help sign in
29 lines 825 B history raw
1## Type Classes
3PureScript has basic support for type classes via the `class` and `instance` keywords.
5Type class instances must be of the form `String`, `Number`, `Boolean`, `[t]` or `C t1 ... tn`, and only a single type class parameter is supported.
7Type class instances are resolved based on the order in which they appeared in the source files. In particular, overlapping instances are permitted.
9```haskell
10class Show a where
11 show :: a -> String
13instance Show String where
14 show s = s
16instance Show Boolean where
17 show true = "true"
18 show false = "false"
20instance (Show a) => Show [a] where
21 show arr = "[" ++ showArray arr ++ "]"
23showArray :: forall a. (Show a) => [a] -> String
24showArray [] = ""
25showArray [x] = show x
26showArray (x:xs) = show x ++ ", " ++ showArray xs
28example = show [true, false]
29```