diff options
| -rw-r--r-- | .gitignore | 4 | ||||
| -rw-r--r-- | examples/types-concept.lisp | 34 | ||||
| -rw-r--r-- | src/Interpreter.hs | 2 | ||||
| -rw-r--r-- | src/Tokenizer.hs | 12 | ||||
| -rw-r--r-- | stdlib/common.lisp | 2 |
5 files changed, 45 insertions, 9 deletions
@@ -1,2 +1,4 @@ .stack-work/ -*~
\ No newline at end of file +*~ + +.DS_Store diff --git a/examples/types-concept.lisp b/examples/types-concept.lisp new file mode 100644 index 0000000..8359c6b --- /dev/null +++ b/examples/types-concept.lisp @@ -0,0 +1,34 @@ +; lowercase types: polymorphic +; everything else: monomorphic + +(type compose (\[ + (\[b] c) ; f + (\[a] b)] ; g + (\[a] c))) +(let! + compose (\[f g] (\[x] (f (g x))))) + +((compose (+ 1) (+ 2)) 3) + +(type id (\[a] a)) +(let! id (\[a] a)) + +(type mod (\[Int Int] Int)) +(let! mod (\[n k] + (- n (* k (/ n k))))) + +(type not (\[Bool] Bool)) +(let! not (\[b] + (match b + true false + false true))) + +(type is-even (\[Int] Bool)) +(let! is-even (\[n] + (match (mod n 2) + 0 true + 1 false))) + +; match cannot be type annotated because its variadic +; but the match above is inferred as this: +(type match (\[a a b a b] b)) diff --git a/src/Interpreter.hs b/src/Interpreter.hs index 1f9153c..52b3a33 100644 --- a/src/Interpreter.hs +++ b/src/Interpreter.hs @@ -320,7 +320,7 @@ runScriptFile fileName = do runInlineScript :: String -> String -> LContext [AST] runInlineScript fileName src = - runInlineScript' 0 fileName src + runInlineScript' 1 fileName src runInlineScript' :: LineNo -> String -> String -> LContext [AST] runInlineScript' lineNo fileName src = do diff --git a/src/Tokenizer.hs b/src/Tokenizer.hs index 777bedb..b38e568 100644 --- a/src/Tokenizer.hs +++ b/src/Tokenizer.hs @@ -97,10 +97,10 @@ tokenize' (row, col) fileName src = do .> filter (\t -> length (tokenContent t) > 0) where - augment row col ('\r':'\n':rest) = - TChar '\n' row col : augment (row + 1) 1 rest - augment row col ('\n':rest) = - TChar '\n' row col : augment (row + 1) 1 rest - augment row col (c:rest) = - TChar c row col : augment row (col + 1) rest + augment row' col' ('\r':'\n':rest) = + TChar '\n' row' col' : augment (row' + 1) 1 rest + augment row' col' ('\n':rest) = + TChar '\n' row' col' : augment (row' + 1) 1 rest + augment row' col' (c:rest) = + TChar c row' col' : augment row' (col' + 1) rest augment _ _ [] = [] diff --git a/stdlib/common.lisp b/stdlib/common.lisp index 2db5d62..efb1183 100644 --- a/stdlib/common.lisp +++ b/stdlib/common.lisp @@ -26,7 +26,7 @@ otherwise (prepend (f (head lst)) (map f (tail lst)))))) -(map (+ 1) [1 2 3]) +; (map (+ 1) [1 2 3]) ;; foldr :: (a -> b -> b) -> b -> [a] -> b (let! foldr (\[f accumulator lst] |
