Skip to content

Commit

Permalink
Merge pull request #3 from garyb/0.10-updates
Browse files Browse the repository at this point in the history
Update for PureScript 0.10
  • Loading branch information
garyb authored Nov 3, 2016
2 parents 84e8e9e + 4d9e076 commit 451f67f
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js
dist: trusty
sudo: required
node_js: 6
node_js: stable
install:
- npm install -g bower
- npm install
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# purescript-fixed-points

[![Latest release](http://img.shields.io/bower/v/purescript-fixed-points.svg)](https://github.com/slamdata/purescript-fixed-points/releases)
[![Build Status](https://travis-ci.org/slamdata/purescript-fixed-points.svg?branch=master)](https://travis-ci.org/slamdata/purescript-fixed-points)
[![Dependency Status](https://www.versioneye.com/user/projects/578d3dce3e6a8b0030c9b38a/badge.svg?style=flat)](https://www.versioneye.com/user/projects/578d3dce3e6a8b0030c9b38a)
[![Latest release](http://img.shields.io/github/release/slamdata/purescript-fixed-points.svg)](https://github.com/slamdata/purescript-fixed-points/releases)
[![Build status](https://travis-ci.org/slamdata/purescript-fixed-points.svg?branch=master)](https://travis-ci.org/slamdata/purescript-fixed-points)

Types for the least (`Mu`) and greatest (`Nu`) fixed points of functors.

Expand Down
5 changes: 3 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"package.json"
],
"dependencies": {
"purescript-exists": "^1.0.0",
"purescript-prelude": "^1.0.0"
"purescript-exists": "^2.0.0",
"purescript-prelude": "^2.1.0",
"purescript-newtype": "^1.1.0"
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
},
"devDependencies": {
"pulp": "^9.0.1",
"purescript": "^0.9.1",
"purescript": "^0.10.1",
"purescript-psa": "^0.3.9",
"rimraf": "^2.5.0"
"rimraf": "^2.5.4"
}
}
10 changes: 6 additions & 4 deletions src/Data/Functor/Mu.purs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Data.Functor.Mu
( Mu
( Mu(..)
, roll
, unroll
) where
Expand All @@ -8,10 +8,11 @@ import Prelude
import Data.TacitString as TS

import Data.Eq1 (class Eq1, eq1)
import Data.Newtype (class Newtype)
import Data.Ord1 (class Ord1, compare1)

-- | `Mu f` is the least fixed point of a functor `f`, when it exists.
data Mu f = In (f (Mu f))
newtype Mu f = In (f (Mu f))

-- | Rewrites a tree along a natural transformation.
transMu
Expand All @@ -32,8 +33,10 @@ roll = In
unroll :: forall f. Mu f -> f (Mu f)
unroll (In x) = x

derive instance newtypeMu :: Newtype (Mu f) _

-- | To implement `Eq`, we require `f` to have higher-kinded equality.
instance eqMu :: (Eq1 f) => Eq (Mu f) where
instance eqMu :: Eq1 f => Eq (Mu f) where
eq (In x) (In y) = eq1 x y

-- | To implement `Ord`, we require `f` to have higher-kinded comparison.
Expand All @@ -45,4 +48,3 @@ instance ordMu :: (Eq1 f, Ord1 f) => Ord (Mu f) where
-- extra quotes from appearing.
instance showMu :: (Show (f TS.TacitString), Functor f) => Show (Mu f) where
show (In x) = show $ x <#> (show >>> TS.hush)

11 changes: 8 additions & 3 deletions src/Data/Functor/Nu.purs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
module Data.Functor.Nu
( Nu
( Nu(..)
, NuF(..)
, Store
, unfold
, observe
) where

import Prelude
import Data.Exists (Exists, mkExists, runExists)
import Data.Newtype (class Newtype)

type Store s a =
{ pos :: s
Expand All @@ -17,15 +20,17 @@ newtype NuF f a = NuF (Store a (f a))
-- | `Nu f` is the greatest fixed point of the functor `f`, when it exists.
newtype Nu f = Nu (Exists (NuF f))

derive instance newtypeNu :: Newtype (Nu f) _

unfold :: forall f a. a -> (a -> f a) -> Nu f
unfold pos peek =
Nu $ mkExists $ NuF
{ pos : pos
, peek : peek
}

observe :: forall f. (Functor f) => Nu f -> f (Nu f)
observe :: forall f. Functor f => Nu f -> f (Nu f)
observe (Nu e) =
runExists
(\(NuF {peek,pos}) -> flip unfold peek <$> peek pos)
(\(NuF { peek, pos }) -> flip unfold peek <$> peek pos)
e
6 changes: 6 additions & 0 deletions src/Data/TacitString.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ module Data.TacitString
) where

import Prelude
import Data.Newtype (class Newtype)

newtype TacitString = TacitString String

derive instance newtypeTacitString :: Newtype TacitString _
derive instance eqTacitString :: Eq TacitString
derive instance ordTacitString :: Ord TacitString

instance showTacitString :: Show TacitString where
show (TacitString str) = str

Expand Down

0 comments on commit 451f67f

Please sign in to comment.