From f0114240cecd453c2be7bb760455f0eb5b7a02a0 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sat, 26 Oct 2024 20:36:13 +0200 Subject: Initial minibruijn --- std/Generic/Monad.bruijn | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 std/Generic/Monad.bruijn (limited to 'std/Generic/Monad.bruijn') diff --git a/std/Generic/Monad.bruijn b/std/Generic/Monad.bruijn new file mode 100644 index 0000000..9e6c5d3 --- /dev/null +++ b/std/Generic/Monad.bruijn @@ -0,0 +1,29 @@ +# MIT License, Copyright (c) 2024 Marvin Borner +# for now, monads, functors, applicative, etc are all in here.. + +# TODO: more monad interface + +:import std/List L + +liftA map ⧗ (a → b) → (M a) → (M b) + +liftA2 ap ∘∘ map ⧗ (a → b → c) → (M a) → (M b) → (M c) + +liftA3 [[[[(liftA2 3 2 1) <*> 0]]]] ⧗ (a → b → c → d) → (M a) → (M b) → (M c) → (M d) + +…<$… map ∘ k ⧗ a → (M b) → (M a) + +…*>… [[(i <$ 1) <*> 0]] ⧗ (M a) → (M b) → (M b) + +…<*… liftA2 k ⧗ (M a) → (M b) → (M a) + +# TODO: traverse, sequence +# in parser: string = traverse char! + +some [y [liftA2 L.cons 1 many]] ⧗ (M a) → (M (List a)) + many 0 <|> (pure L.empty) + +many [y [some <|> (pure L.empty)]] ⧗ (M a) → (M (List a)) + some liftA2 L.cons 1 0 + +between [[[2 *> 0 <* 1]]] ⧗ (M a) → (M a) → (M a) → (M a) -- cgit v1.2.3