-
Notifications
You must be signed in to change notification settings - Fork 72
/
07-Multi-Paramter.purs
34 lines (24 loc) · 923 Bytes
/
07-Multi-Paramter.purs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module Syntax.Basic.Typeclass.MultiParameters where
import Prelude
-- A type class can have more than just a single parameter as its type.
-- Syntax
class MultiParameterTypeClass1 type1 type2 {- typeN -} where
functionName1 :: type1 -> type2 -> {- typeN -> -} ReturnType
-- Again, a parameter could be the return type
class MultiParameterTypeClass2 type1 type2 {- typeN -} where
functionName2 :: Int -> type1 -> {- typeN -> -} type2
-- example (not practical, but gets the idea across)
class ConvertFromAToB a b where
convert :: a -> b
instance ConvertFromAToB Boolean String where
convert true = "true"
convert false = "false"
instance ConvertFromAToB Boolean Int where
convert true = 1
convert false = 0
toString :: forall a. ConvertFromAToB a String => a -> String
toString a = convert a
test :: Boolean
test = (toString true) == "true"
-- necessary to make file compile
type ReturnType = String