Skip to content

Commit

Permalink
Merge pull request #6 from garyb/0.10-updates
Browse files Browse the repository at this point in the history
Update dependencies
  • Loading branch information
ethul authored Oct 24, 2016
2 parents cb60f2a + 2d5b8a0 commit 9ccd7db
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 81 deletions.
14 changes: 7 additions & 7 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
"url": "git://github.com/ethul/purescript-freeap.git"
},
"dependencies": {
"purescript-exists": "^1.0.0",
"purescript-const": "^1.0.0"
"purescript-exists": "^2.0.0",
"purescript-const": "^2.0.0"
},
"devDependencies": {
"purescript-either": "^1.0.0",
"purescript-integers": "^1.0.0",
"purescript-generics": "^1.0.0",
"purescript-console": "^1.0.0",
"purescript-exceptions": "~1.0.0"
"purescript-either": "^2.0.0",
"purescript-integers": "^2.0.0",
"purescript-generics": "^3.1.0",
"purescript-console": "^2.0.0",
"purescript-exceptions": "^2.0.0"
}
}
130 changes: 62 additions & 68 deletions docs/Control/Applicative/Free.md
Original file line number Diff line number Diff line change
@@ -1,68 +1,62 @@
## Module Control.Applicative.Free

#### `FreeAp`

``` purescript
data FreeAp f a
```

The free applicative functor for a type constructor `f`.

##### Instances
``` purescript
Functor (FreeAp f)
Apply (FreeAp f)
Applicative (FreeAp f)
```

#### `NaturalTransformation`

``` purescript
type NaturalTransformation f g = forall a. f a -> g a
```

#### `liftFreeAp`

``` purescript
liftFreeAp :: forall f a. f a -> FreeAp f a
```

Lift a value described by the type constructor `f` into
the free applicative functor.

#### `retractFreeAp`

``` purescript
retractFreeAp :: forall f a. (Applicative f) => FreeAp f a -> f a
```

Run a free applicative functor using the applicative instance for
the type constructor `f`.

#### `foldFreeAp`

``` purescript
foldFreeAp :: forall f g a. (Applicative g) => NaturalTransformation f g -> FreeAp f a -> g a
```

Run a free applicative functor with a natural transformation from
the type constructor `f` to the applicative functor `g`.

#### `hoistFreeAp`

``` purescript
hoistFreeAp :: forall f g a. NaturalTransformation f g -> FreeAp f a -> FreeAp g a
```

Natural transformation from `FreeAp f a` to `FreeAp g a` given a
natural transformation from `f` to `g`.

#### `analyzeFreeAp`

``` purescript
analyzeFreeAp :: forall f m a. (Monoid m) => (forall b. f b -> m) -> FreeAp f a -> m
```

Perform monoidal analysis over the free applicative functor `f`.


## Module Control.Applicative.Free

#### `FreeAp`

``` purescript
data FreeAp f a
```

The free applicative functor for a type constructor `f`.

##### Instances
``` purescript
Functor (FreeAp f)
Apply (FreeAp f)
Applicative (FreeAp f)
```

#### `liftFreeAp`

``` purescript
liftFreeAp :: forall f a. f a -> FreeAp f a
```

Lift a value described by the type constructor `f` into
the free applicative functor.

#### `retractFreeAp`

``` purescript
retractFreeAp :: forall f a. Applicative f => FreeAp f a -> f a
```

Run a free applicative functor using the applicative instance for
the type constructor `f`.

#### `foldFreeAp`

``` purescript
foldFreeAp :: forall f g a. Applicative g => (f ~> g) -> FreeAp f a -> g a
```

Run a free applicative functor with a natural transformation from
the type constructor `f` to the applicative functor `g`.

#### `hoistFreeAp`

``` purescript
hoistFreeAp :: forall f g a. (f ~> g) -> FreeAp f a -> FreeAp g a
```

Natural transformation from `FreeAp f a` to `FreeAp g a` given a
natural transformation from `f` to `g`.

#### `analyzeFreeAp`

``` purescript
analyzeFreeAp :: forall f m a. Monoid m => (forall b. f b -> m) -> FreeAp f a -> m
```

Perform monoidal analysis over the free applicative functor `f`.


13 changes: 7 additions & 6 deletions src/Control/Applicative/Free.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ module Control.Applicative.Free
, analyzeFreeAp
) where

import Prelude (class Applicative, class Apply, class Functor, type (~>), Unit, (<<<), apply, flip, id, map, pure, unit)
import Prelude hiding (ap)

import Data.Const (Const(Const), getConst)
import Data.Const (Const(..))
import Data.Exists (Exists, mkExists, runExists)
import Data.Monoid (class Monoid)
import Data.Newtype (unwrap)

-- | The free applicative functor for a type constructor `f`.
data FreeAp f a = Pure a | Ap (Exists (ApF f a))
Expand All @@ -28,13 +29,13 @@ liftFreeAp a = ap (\_ -> a) (\_ -> Pure id)

-- | Run a free applicative functor using the applicative instance for
-- | the type constructor `f`.
retractFreeAp :: forall f a. (Applicative f) => FreeAp f a -> f a
retractFreeAp :: forall f a. Applicative f => FreeAp f a -> f a
retractFreeAp (Pure a) = pure a
retractFreeAp (Ap x) = runExists (\(ApF v k') -> apply (retractFreeAp (k' unit)) (v unit)) x

-- | Run a free applicative functor with a natural transformation from
-- | the type constructor `f` to the applicative functor `g`.
foldFreeAp :: forall f g a. (Applicative g) => (f ~> g) -> FreeAp f a -> g a
foldFreeAp :: forall f g a. Applicative g => (f ~> g) -> FreeAp f a -> g a
foldFreeAp k (Pure a) = pure a
foldFreeAp k (Ap x) = runExists (\(ApF v k') -> apply (map (flip id) (k (v unit))) (foldFreeAp k (k' unit))) x

Expand All @@ -45,8 +46,8 @@ hoistFreeAp k (Pure a) = Pure a
hoistFreeAp k (Ap x) = runExists (\(ApF v k') -> ap (\_ -> k (v unit)) (\_ -> hoistFreeAp k (k' unit))) x

-- | Perform monoidal analysis over the free applicative functor `f`.
analyzeFreeAp :: forall f m a. (Monoid m) => (forall b. f b -> m) -> FreeAp f a -> m
analyzeFreeAp k = getConst <<< foldFreeAp (Const <<< k)
analyzeFreeAp :: forall f m a. Monoid m => (forall b. f b -> m) -> FreeAp f a -> m
analyzeFreeAp k = unwrap <<< foldFreeAp (Const <<< k)

instance functorFreeAp :: Functor (FreeAp f) where
map k (Pure a) = Pure (k a)
Expand Down

0 comments on commit 9ccd7db

Please sign in to comment.