Changeset 32835 in project


Ignore:
Timestamp:
10/24/15 20:24:51 (5 years ago)
Author:
svnwiki
Message:

Anonymous wiki edit for IP [70.67.150.22]: Docs were way out of date

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/monad

    r32343 r32835  
    77== Description
    88
     9*[[https://github.com/dleslie/monad-egg/issues|Please file Issues]] if you find a bug or need help; I will attempt to address them!*
     10
    911=== What is a Monad?
    1012
     
    1517Monads are types that have:
    1618
    17 1. A binding function of the form: a -> (a -> M b) -> M b
     191. A binding function of the form: M a -> (a -> M b) -> M b
    1820
    19212. A unit function: a -> M a
     
    213215(do-using <maybe>
    214216          (x <- (return 1))
    215           (if (eq? 2 (cadr x))
     217          (if (eq? 2 x)
    216218              (return 'Banana)
    217219              (fail))
     
    223225</enscript>
    224226
    225 ==== (do monad [body ...])
    226 
    227 <macro>(do monad [body ...])</macro>
     227==== (do/m monad [body ...])
     228
     229<macro>(do/m monad [body ...])</macro>
    228230
    229231Alias for (do-using monad [body ...]).
     
    248250  <maybe>
    249251  (lambda (a) a)
    250   (lambda (a f) (if a (f a) #f))
     252  (lambda (a f) (if a (f (cadr a)) #f))
    251253  (case-lambda (() 'Nothing)
    252254               ((_ . _) 'Nothing)))
     
    256258
    257259<enscript highlight="scheme">
    258 > (do <maybe>
     260> (do/m <maybe>
    259261      (if #t
    260262          'Nothing
     
    276278
    277279<enscript highlight="scheme">
    278 #;> (do <list>
     280#;> (do/m <list>
    279281        (x <- '(1 2 3))
    280282        (y <- '(a b c))
     
    308310
    309311<enscript highlight="scheme">
    310 #;> ((do <state>
     312#;> ((do/m <state>
    311313         (x <- (/m get))
    312314         (return x))
     
    324326
    325327<enscript highlight="scheme">
    326 #;> ((do <state>
     328#;> ((do/m <state>
    327329         (x <- (/m! gets (lambda (s) (+ s 1))))
    328330         (return x))
     
    340342
    341343<enscript highlight="scheme">
    342 #;> ((do <state>
     344#;> ((do/m <state>
    343345         (/m! modify (lambda (v)
    344346                      (display (format "Received: ~S\n" v))
     
    358360
    359361<enscript highlight="scheme">
    360 #;> ((do <state>
     362#;> ((do/m <state>
    361363         (/m! put 1))
    362364     2)
     
    384386
    385387<enscript highlight="scheme">
    386 #;> ((do <reader>
     388#;> ((do/m <reader>
    387389         (x <- (/m ask))
    388390         (return (+ x 1)))
     
    400402
    401403<enscript highlight="scheme">
    402 #;> ((do <reader>
     404#;> ((do/m <reader>
    403405         (/m! asks (lambda (v)
    404406                    (+ v 1))))
     
    416418
    417419<enscript highlight="scheme">
    418 #;> ((do <reader>
     420#;> ((do/m <reader>
    419421         (/m! local
    420422             (lambda (v) (+ v 1))
    421              (do <reader>
     423             (do/m <reader>
    422424                 (x <- (/m ask))
    423425                 (return x))))
     
    465467
    466468<enscript highlight="scheme">
    467 #;> (do <exception> (/m! throw "Error! No more cheerios!"))
     469#;> (do/m <exception> (/m! throw "Error! No more cheerios!"))
    468470(failure "Error! No more cheerios!")
    469471</enscript>
     
    479481<enscript highlight="scheme">
    480482#;> (define some-monad
    481             (do <exception>
     483            (do/m <exception>
    482484                (/m! throw "An error happened! Oh no!")))
    483 #;> (do <exception>
     485#;> (do/m <exception>
    484486        (/m! catch some-monad
    485487                  (lambda (m)
     
    511513
    512514<enscript highlight="scheme">
    513 #;> (do <writer> (/m! tell '(1 2 3)))
     515#;> (do/m <writer> (/m! tell '(1 2 3)))
    514516(() 1 2 3)
    515517</enscript>
     
    524526
    525527<enscript highlight="scheme">
    526 #;> (do <writer>
     528#;> (do/m <writer>
    527529        (x <- (/m! listen
    528530                  (/m! tell '(foo))))
     
    540542
    541543<enscript highlight="scheme">
    542 #;> (do <writer>
     544#;> (do/m <writer>
    543545        (x <- (return (/m! tell '(1 2 3))))
    544546        (/m! listens
     
    559561
    560562<enscript highlight="scheme">
    561 #;> (do <writer>
     563#;> (do/m <writer>
    562564        (x <- (/m! listen
    563565                  `((() . ,(lambda (l)
     
    577579
    578580<enscript highlight="scheme">
    579 #;> (do <writer>
     581#;> (do/m <writer>
    580582        (/m! censor (lambda (l) (map (lambda (v) (+ v 1)) l))
    581583                   (/m! tell '(1 2 3))))
     
    598600=== Version History
    599601
     602; 4.1 : Fixed #7, updated readme.org
     603; 4.0 : Dropped Exception and CPS, as they did not work under basic tests; removed do keyword, fixed Writer monad
     604; 3.3 : Total rewrite, no API changes
     605; 3.2 : Minor syntax change
    600606; 3.0 : Renamed :! to /m! and : to /m due to : already being used for explicit specialization (oops)                                                                                                                                                                     
    601607; 2.4 : Added :! keyword, fixed : keyword                                                                                                                                                                                                                               
Note: See TracChangeset for help on using the changeset viewer.