types1.hs
and put these lines in it:
add x y = x + y addInt::Int -> Int -> Int addInt x y = x + y i = 10 j = 10 k = addInt i i f1 = add 10 f2 = addInt 10 -- (end of lines for file) --Then...
:load
and then do :browse
to see the types of the bindings.
:type
s, and let
bindings follow some of which produce errors. Go through them, first trying to predict the result, and then seeing what actually happens. If an error, see if you can understand its cause.
i j k add i i add j j addInt i i addInt j j let i2 = 5 :type i2 let i3 = 5::Int :type i3 addInt i2 i2 addInt i3 i3
min3
and eq3
from slide 81 to types1.hs
and then use :r
to reload it. See what :browse
now shows.
eq3 i i i eq3 j j j eq3 i j i min3 i 1 2 min3 i 100 23432423423423423432423242423423 -- Actual value not important. Try several big integers! What's going on?!
:type
to see the type of each of the following functions, you'll see that some type variables are a's
, b's
, etc. and some are t
, t1
, t2
, etc. See if you can discern a pattern in which of the two sequences the type variable is chosen from.
let f1 x = x let f2 x = 10 let f3 x y z = y let f4 x y z = x ^ y + 0