diff options
author | Marvin Borner | 2024-10-26 20:36:13 +0200 |
---|---|---|
committer | Marvin Borner | 2024-10-26 20:49:11 +0200 |
commit | f0114240cecd453c2be7bb760455f0eb5b7a02a0 (patch) | |
tree | 25701a05e4bf6df011baca7a3ac9c2ce653c3882 /samples/fun | |
parent | 072707de34348a1c01eeeb90006c5ca828d2a992 (diff) |
Initial minibruijn
Diffstat (limited to 'samples/fun')
-rw-r--r-- | samples/fun/minibruijn.bruijn | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/samples/fun/minibruijn.bruijn b/samples/fun/minibruijn.bruijn new file mode 100644 index 0000000..1364983 --- /dev/null +++ b/samples/fun/minibruijn.bruijn @@ -0,0 +1,33 @@ +# MIT License, Copyright (c) 2024 Marvin Borner + +:import std/Char C +:import std/Combinator . +:import std/List . +:import std/Meta M +:import std/Monad/Parser . +:import std/Number/Conversion O +:import std/Result R + +# meta encoding uses Church numerals instead of binary! +char→number (\C.sub '0') → O.binary→unary + +identifier satisfy (c ∘ C.space?) + +spaces many (satisfy C.space?) + +newlines some (satisfy (C.eq? '\n')) + +parens between (char '(') (char ')') + +number char→number <$> (satisfy C.numeric?) + +term y [(foldl1 M.app) <$> (some (spaces *> singleton <* spaces))] + singleton abs <|> idx <|> (parens 0) + abs M.abs <$> (between (char '[') (char ']') 0) + idx M.idx <$> number + +block identifier <*> term + +program block >>= newlines + +main (M.eval <$> term) → [0 i i] |