The reason this doesn’t work is that the caller of a polymorphic function gets to choose the type. Here we, the implementors, have tried to choose a specific type
could be understood as a promise that a function with this type will work no matter what type the caller chooses
Type classes
Intuitively, type classes correspond to sets of types which have certain operations defined for them, and type class polymorphic functions work only for types which are instances of the type class(es) in question
Home Work
Exercise 1
Exercise 2
Exercise 3
Defination for Expr
Exercise 4
Exercise 5
Exercise 6
There are two tricky parts from my view:
Same expression can belong to multiple types,
both add (lit 3) (var "x") :: (M.Map String Integer -> Maybe Integer) and add (lit 3) (var "x") :: VarExprT are valid
add e1 e2 m has the type of (M.Map String Integer -> Maybe Integer) -> (M.Map String Integer -> Maybe Integer) -> (M.Map String Integer -> Maybe Integer)