mirror of
https://github.com/Noratrieb/idris-learning.git
synced 2026-01-14 13:05:02 +01:00
more
This commit is contained in:
parent
b9c358c622
commit
5a58f22743
2 changed files with 34 additions and 0 deletions
|
|
@ -91,3 +91,26 @@ listToTree xs = listToTreeInner xs Empty
|
||||||
listToTreeInner : List elem -> BSTree elem -> BSTree elem
|
listToTreeInner : List elem -> BSTree elem -> BSTree elem
|
||||||
listToTreeInner [] tree = tree
|
listToTreeInner [] tree = tree
|
||||||
listToTreeInner (x :: xs) tree = insert x (listToTreeInner xs tree)
|
listToTreeInner (x :: xs) tree = insert x (listToTreeInner xs tree)
|
||||||
|
|
||||||
|
|
||||||
|
treeToList : BSTree elem -> List elem
|
||||||
|
treeToList Empty = []
|
||||||
|
treeToList (Node left val right) = treeToList left ++ val :: treeToList right
|
||||||
|
|
||||||
|
|
||||||
|
-- expression
|
||||||
|
data Expr = Val Int
|
||||||
|
| Add Expr Expr
|
||||||
|
| Sub Expr Expr
|
||||||
|
| Mult Expr Expr
|
||||||
|
|
||||||
|
evaluate : Expr -> Int
|
||||||
|
evaluate (Val x) = x
|
||||||
|
evaluate (Add x y) = (evaluate x) + (evaluate y)
|
||||||
|
evaluate (Sub x y) = (evaluate x) - (evaluate y)
|
||||||
|
evaluate (Mult x y) = (evaluate x) * (evaluate y)
|
||||||
|
|
||||||
|
maxMaybe : Ord a => Maybe a -> Maybe a -> Maybe a
|
||||||
|
maxMaybe Nothing y = y
|
||||||
|
maxMaybe x Nothing = x
|
||||||
|
maxMaybe a@(Just x) b@(Just y) = if x > y then a else b
|
||||||
|
|
|
||||||
11
projects/Brainfuck.idr
Normal file
11
projects/Brainfuck.idr
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
module Brainfuck
|
||||||
|
|
||||||
|
import Data.Vect
|
||||||
|
|
||||||
|
data Memory = End
|
||||||
|
| Value Memory Int Memory
|
||||||
|
|
||||||
|
|
||||||
|
emptyMemory : Nat -> Memory
|
||||||
|
emptyMemory Z = End
|
||||||
|
emptyMemory S(k) = Value 0 (emptyMemory k)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue