Skip to content

Commit

Permalink
asd
Browse files Browse the repository at this point in the history
  • Loading branch information
ranjitjhala committed Oct 8, 2018
1 parent 037382d commit 3f3629c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 15 deletions.
6 changes: 6 additions & 0 deletions lectures/01-introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
8 changes: 4 additions & 4 deletions lectures/03-adder.md
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ asm1 = [ IMov (EAX) (Const 7)
```

```haskell
src1 = "add1(add1(12))"
src2 = "add1(add1(12))"

exp2 = Add1 (Add1 (Number 12))

Expand Down Expand Up @@ -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)
]
```

Expand Down
51 changes: 40 additions & 11 deletions static/hs/CrashCourse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module CrashCourse where




import Debug.Trace (trace)

{-
[a] -> [b] -> [(a, b)]
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 3f3629c

Please sign in to comment.