aboutsummaryrefslogtreecommitdiff

Scheme Monads

In an attempt to understand how Monads in Haskell actually works I set out to reimplement them myself in scheme.

Examples

(use-modules (monad)
             (monad state))

(run-state (do x <- (<$> sqrt (get))
               let y = (+ x 10)
               (put y)
               (return-state x))
           64)
;; => (8 18)

(>> (just 1)
    (just 2))
;; => [Just 2]

Unfortunately, it doesn't really short circuit as one would have hoped:

(>> (nothing) (just (/ 1 0)))
<unnamed port>:1520:36: Throw to key `numerical-overflow' with args `("/"
"Numerical overflow" #f #f)'.

Usage

The module (monad) contains all base bindings, allowing usage of the monad system. The modules (monad *) contains different data types, including optional, stacks, and more.

Documentation

Documentation can be build with

make doc

It however doesn't work to well, since the (texinfo reflection) modules is less than perfect.

Tests & Examples

tests/test.scm contains a few tests and examples of how to use the code.


cloc github.com/AlDanial/cloc v 1.90 T=0.21 s (46.9 files/s, 2699.2 lines/s)
Language files blank comment code
Scheme 8 101 77 325
Markdown 1 14 0 35
make 1 8 0 15
-------- -------- -------- -------- --------
SUM: 10 123 77 375