Theory and Design of PL (CS 538)
February 10, 2020
42
, 'a'
, []
, (x:xs)
, (x, y)
i < 0
, b == False
foo :: (Bool, (Int, String)) -> String
foo (b, (i, c)) = ... b ... i ... c ...
-- SAME AS:
-- foo p = ... (fst p) ... (fst . snd $ p) ... (snd . snd $ p)
bar :: (Int, String) -> String
bar (1, str) = str ++ " one!"
bar (2, str) = str ++ " two!"
bar (_, str) = str ++ " something!"
-- BUT NOT:
-- baz :: Int -> String
-- baz (i < 0) = ...
Code that is part of some expression should be indented further in than the beginning of that expression, even if the expression is not the first element of line.
;
and { ... }
(foo 0) + 1
(foo 0)
is not a numeric expression
foo
returns a boolean?For our purposes: booleans and integers
base-ty = "bool" | "int"
ty = base-ty | ty "->" ty
true
has type bool
42
has type int
plusOne = λx. x + 1
has type int -> int
true + 1
is stuckplusOne = λx. x + 2
(if true then 0 else false) + 1