Skip to content

Commit 4dcc233

Browse files
committed
Initial commit
0 parents  commit 4dcc233

File tree

5 files changed

+102
-0
lines changed

5 files changed

+102
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/js/
2+
/externs/
3+
/node_modules/
4+
/bower_components/

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014 PureScript
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

bower.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "purescript-control",
3+
"version": "0.0.0",
4+
"homepage": "https://github.com/purescript/purescript-control",
5+
"description": "Monad and Applicative utility functions",
6+
"keywords": [
7+
"purescript"
8+
],
9+
"license": "MIT",
10+
"ignore": [
11+
"**/.*",
12+
"node_modules",
13+
"bower_components",
14+
"examples",
15+
"externs",
16+
"js"
17+
],
18+
"dependencies": {
19+
"purescript-foldable-traversable": "*"
20+
}
21+
}

src/Control/Applicative.purs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module Control.Applicative where
2+
3+
import Prelude
4+
5+
infixl 4 <*
6+
infixl 4 *>
7+
8+
(<*) :: forall a b f. (Applicative f) => f a -> f b -> f a
9+
(<*) x y = const <$> x <*> y
10+
11+
(*>) :: forall a b f. (Applicative f) => f a -> f b -> f b
12+
(*>) x y = const id <$> x <*> y
13+
14+
lift2 :: forall a b c f. (Applicative f) => (a -> b -> c) -> f a -> f b -> f c
15+
lift2 f x y = f <$> x <*> y
16+
17+
lift3 :: forall a b c d f. (Applicative f) => (a -> b -> c -> d) -> f a -> f b -> f c -> f d
18+
lift3 f x y z = f <$> x <*> y <*> z
19+
20+
zipWithA :: forall m a b c. (Applicative m) => (a -> b -> m c) -> [a] -> [b] -> m [c]
21+
zipWithA f xs ys = sequence (zipWith f xs ys)

src/Control/Monad.purs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
module Control.Monad where
2+
3+
import Prelude
4+
import Data.Array
5+
import Data.Traversable
6+
7+
replicateM :: forall m a. (Monad m) => Number -> m a -> m [a]
8+
replicateM 0 _ = return []
9+
replicateM n m = do
10+
a <- m
11+
as <- replicateM (n - 1) m
12+
return (a : as)
13+
14+
infixr 1 >=>
15+
infixr 1 <=<
16+
17+
(>=>) :: forall m a b c. (Monad m) => (a -> m b) -> (b -> m c) -> a -> m c
18+
(>=>) f g a = do
19+
b <- f a
20+
g b
21+
22+
(<=<) :: forall m a b c. (Monad m) => (b -> m c) -> (a -> m b) -> a -> m c
23+
(<=<) = flip (>=>)
24+
25+
join :: forall m a. (Monad m) => m (m a) -> m a
26+
join mm = do
27+
m <- mm
28+
m
29+
30+
foldM :: forall m a b. (Monad m) => (a -> b -> m a) -> a -> [b] -> m a
31+
foldM _ a [] = return a
32+
foldM f a (b:bs) = f a b >>= \a' -> foldM f a' bs
33+
34+
when :: forall m. (Monad m) => Boolean -> m {} -> m {}
35+
when true m = m
36+
when false _ = return {}

0 commit comments

Comments
 (0)