From 3f3629c33ab5620d4a43500579462071296f7bbe Mon Sep 17 00:00:00 2001 From: Ranjit Jhala Date: Mon, 8 Oct 2018 11:28:52 -0700 Subject: [PATCH] asd --- lectures/01-introduction.md | 6 +++++ lectures/03-adder.md | 8 +++--- static/hs/CrashCourse.hs | 51 +++++++++++++++++++++++++++++-------- 3 files changed, 50 insertions(+), 15 deletions(-) diff --git a/lectures/01-introduction.md b/lectures/01-introduction.md index 386e900..83f8a9f 100644 --- a/lectures/01-introduction.md +++ b/lectures/01-introduction.md @@ -244,3 +244,9 @@ Here are some links to get you started: [hoogle]: https://www.haskell.org/hoogle/ [haskell-for-ocamlers]: http://science.raphael.poss.name/haskell-for-ocaml-programmers.html [soap-fortran-assembly]: http://worrydream.com/dbx/ + + + +["cat", "dog", "horse"] -- :: [String] -- words + String -- separator +"cat;dog;horse" -- :: String -- "crunche words with separator" diff --git a/lectures/03-adder.md b/lectures/03-adder.md index 053b908..659bb83 100644 --- a/lectures/03-adder.md +++ b/lectures/03-adder.md @@ -420,7 +420,7 @@ asm1 = [ IMov (EAX) (Const 7) ``` ```haskell -src1 = "add1(add1(12))" +src2 = "add1(add1(12))" exp2 = Add1 (Add1 (Number 12)) @@ -496,13 +496,13 @@ ghci> (compile (Number 12) ghci> compile (Add1 (Number 12)) [ IMov (Reg EAX) (Const 12) -, IADd (Reg EAX) (Const 1) +, IAdd (Reg EAX) (Const 1) ] ghci> compile (Add1 (Add1 (Number 12))) [ IMov (Reg EAX) (Const 12) -, IADd (Reg EAX) (Const 1) -, IADd (Reg EAX) (Const 1) +, IAdd (Reg EAX) (Const 1) +, IAdd (Reg EAX) (Const 1) ] ``` diff --git a/static/hs/CrashCourse.hs b/static/hs/CrashCourse.hs index 1c50034..4d3a86a 100644 --- a/static/hs/CrashCourse.hs +++ b/static/hs/CrashCourse.hs @@ -3,7 +3,7 @@ module CrashCourse where - +import Debug.Trace (trace) {- [a] -> [b] -> [(a, b)] @@ -156,13 +156,47 @@ qsort (h:t) = qsort ls ++ [h] ++ qsort rs -- (ls,rs) = partition (\x -> x < h) t -data Mond - = MNumber Double - | MPlus Mond Mond - | MMinus Mond Mond - | MTimes Mond Mond +data Mond a + = MNumber a + | MPlus (Mond a) (Mond a) + | MMinus (Mond a) (Mond a) + | MTimes (Mond a) (Mond a) deriving (Show) +m0 = MNumber 1 +m1 = MNumber 3 +m2 = MPlus m0 m1 +m3 = MMinus m0 m1 +m4 = MTimes m2 m3 + +evalMond m = let res = case m of + (MNumber d) -> d + (MPlus m1 m2) -> evalMond m1 + evalMond m2 + (MMinus m1 m2) -> evalMond m1 - evalMond m2 + (MTimes m1 m2) -> evalMond m1 - evalMond m2 + msg = show ("evalMond", m, res) + in + trace msg res +{- +def facto(n): + if n <= 0: + res = 0 + else: + res = n * facto(n-1) + print "facto: ", n, res + return res + -} + + + +facto :: Int -> Int +facto n = let res = if n <= 0 then 0 else n * facto (n-1) + msg = show ("facto", n, res) + in + trace msg res + + + {- What is "the type of" `MPlus` ? A. Go away (error) @@ -171,11 +205,6 @@ C. (Mond, Mond) D. Other -} -A. Rubios -B. Taco Villa -C. Goodys -D. Pines - {- (* val sort : 'a list -> 'a list *) let rec sort xs = match xs with