diff --git a/input.txt b/input.txt deleted file mode 100644 index 1ba8437..0000000 --- a/input.txt +++ /dev/null @@ -1,4 +0,0 @@ -1abc2 -pqr3stu8vwx -a1b2c3d4e5f -treb7uchet \ No newline at end of file diff --git a/justfile b/justfile index 1c3a9d2..ff83977 100644 --- a/justfile +++ b/justfile @@ -10,7 +10,7 @@ test: # Run the project with ghcid auto-recompile run: - stack build --file-watch --fast --ghc-options='-O0 -fbyte-code' --exec "elara --dump-shunted --dump-core --dump-typed --run" + stack build --file-watch --fast --ghc-options='-O1 -fbyte-code' --exec "elara --dump-shunted --dump-core --dump-typed --run" # Start Hoogle server for project dependencies docs: diff --git a/list.elr b/list.elr index f2f4486..881d676 100644 --- a/list.elr +++ b/list.elr @@ -5,4 +5,54 @@ def isEmpty : [a] -> Bool let isEmpty l = match l with [] -> True - (x::xs) -> False \ No newline at end of file + (x::xs) -> False + +def length : [a] -> Int +let length l = + match l with + [] -> 0 + (x::xs) -> 1 + length xs + +def sum : [Int] -> Int +let sum a = + match a with + [] -> 0 + (x::xs) -> x + sum xs + +def reverse : [a] -> [a] +let reverse a = + match a with + [] -> [] + (x::xs) -> reverse xs <> [x] + +def head : [a] -> a +let head a = + match a with + [] -> undefined + (x::xs) -> x + +def last : [a] -> a +let last a = + match a with + [] -> undefined + (x::xs) -> if xs == [] then x else last xs + + +def map : (a -> b) -> [a] -> [b] +let map f a = + match a with + [] -> [] + (x::xs) -> f x :: map f xs + +def filter : (a -> Bool) -> [a] -> [a] +let filter f a = + match a with + [] -> [] + (x::xs) -> if f x then x :: filter f xs else filter f xs + +infixr 5 <> +def (<>) : [a] -> [a] -> [a] +let (<>) a b = + match a with + [] -> b + (x::xs) -> x :: (xs <> b) \ No newline at end of file diff --git a/prelude.elr b/prelude.elr index 92cd66b..0b7e944 100644 --- a/prelude.elr +++ b/prelude.elr @@ -42,50 +42,13 @@ let charToInt c = else if c == '9' then 9 else -1 -infixr 5 <> -def (<>) : [a] -> [a] -> [a] -let (<>) a b = - match a with - [] -> b - (x::xs) -> x :: (xs <> b) + infixr 5 ++ def (++) : String -> String -> String let (++) a b = listToString ((stringToList a) <> (stringToList b)) -def reverse : [a] -> [a] -let reverse a = - match a with - [] -> [] - (x::xs) -> reverse xs <> [x] - - -def head : [a] -> a -let head a = - match a with - [] -> undefined - (x::xs) -> x - -def last : [a] -> a -let last a = - match a with - [] -> undefined - (x::xs) -> if xs == [] then x else last xs - - -def map : (a -> b) -> [a] -> [b] -let map f a = - match a with - [] -> [] - (x::xs) -> f x :: map f xs - -def filter : (a -> Bool) -> [a] -> [a] -let filter f a = - match a with - [] -> [] - (x::xs) -> if f x then x :: filter f xs else filter f xs - def not : Bool -> Bool let not a = if a then False else True @@ -95,18 +58,6 @@ let (/=) a b = not (a == b) -def sum : [Int] -> Int -let sum a = - match a with - [] -> 0 - (x::xs) -> x + sum xs - -def isEmpty : [a] -> Bool -let isEmpty a = - match a with - [] -> True - (x::xs) -> False - def listToString : [Char] -> String let listToString a = match a with diff --git a/source.elr b/source.elr index d8579ae..ef491c6 100644 --- a/source.elr +++ b/source.elr @@ -4,11 +4,5 @@ import Elara.Prim def l : List Int let l = [1, 2, 3] -def map : (a -> b) -> List a -> List b -let map f l = - match l with - Nil -> Nil - Cons x xs -> Cons (f x) (map f xs) - let main = - print (stringToList "hello") + print (stringToList "hello" |> map identity |> length)