From f0114240cecd453c2be7bb760455f0eb5b7a02a0 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sat, 26 Oct 2024 20:36:13 +0200 Subject: Initial minibruijn --- samples/fun/minibruijn.bruijn | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 samples/fun/minibruijn.bruijn (limited to 'samples/fun/minibruijn.bruijn') 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] -- cgit v1.2.3