Skip to content

Instantly share code, notes, and snippets.

@apaleslimghost
Forked from robotlolita/control.monad.basics.ls
Last active December 29, 2015 22:19
Show Gist options
  • Select an option

  • Save apaleslimghost/7735552 to your computer and use it in GitHub Desktop.

Select an option

Save apaleslimghost/7735552 to your computer and use it in GitHub Desktop.

Revisions

  1. @quarterto quarterto revised this gist Dec 1, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion control.monad.basics.ls
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    #
    # + type: (Monad m) => m -> [m a] -> m [a]
    export sequence = (m, ms) --> do
    return ms.reduce-right perform, m.of []
    return ms.reduce perform, m.of []
    # where:
    function perform(m1, m2) => do
    x <- m1.chain
  2. @quarterto quarterto revised this gist Dec 1, 2013. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions control.monad.basics.ls
    Original file line number Diff line number Diff line change
    @@ -10,5 +10,4 @@ export sequence = (m, ms) --> do
    function perform(m1, m2) => do
    x <- m1.chain
    xs <- m2.chain
    xs.push x
    m.of xs
    m.of x ++ xs
  3. Quildreen Motta revised this gist Nov 27, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion control.monad.basics.ls
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    #
    # + type: (Monad m) => m -> [m a] -> m [a]
    export sequence = (m, ms) --> do
    return (`ms.reduce-right` m.of []) perform
    return ms.reduce-right perform, m.of []
    # where:
    function perform(m1, m2) => do
    x <- m1.chain
  4. Quildreen Motta revised this gist Nov 27, 2013. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions sequence.hs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    -- | Evaluate each action in the sequence from left to right,
    -- and collect the results.
    sequence :: Monad m => [m a] -> m [a]

    sequence ms = foldr k (return []) ms
    where
    k m m' = do { x <- m; xs <- m'; return (x:xs) }
  5. Quildreen Motta created this gist Nov 27, 2013.
    14 changes: 14 additions & 0 deletions control.monad.basics.ls
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    # ## Function: sequence
    #
    # Evaluates each action in sequence, left to right, collecting the
    # results.
    #
    # + type: (Monad m) => m -> [m a] -> m [a]
    export sequence = (m, ms) --> do
    return (`ms.reduce-right` m.of []) perform
    # where:
    function perform(m1, m2) => do
    x <- m1.chain
    xs <- m2.chain
    xs.push x
    m.of xs