Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

Commit

Permalink
prepare first release, ref #21 (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti authored Sep 12, 2016
1 parent 74df99e commit 6f6bfea
Show file tree
Hide file tree
Showing 77 changed files with 204 additions and 223 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": ["es2015"],
"presets": ["es2015", "react"],
"plugins" : [
"syntax-flow",
"transform-flow-strip-types",
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.log
node_modules
dev
lib
node_modules
5 changes: 0 additions & 5 deletions .npmignore

This file was deleted.

17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Changelog

> **Tags:**
> - [New Feature]
> - [Bug Fix]
> - [Breaking Change]
> - [Documentation]
> - [Internal]
> - [Polish]
> - [Experimental]
**Note**: Gaps between patch versions are faulty/broken releases.
**Note**: A feature tagged as Experimental is in a high state of flux, you're at risk of it changing without notice.

## 0.1.0

Initial release
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Giulio Canti

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
88 changes: 20 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,15 @@

- statically type checked by [Flow](https://flowtype.org/)
- PureScript-like standard library
- static land compatible ([Specification](https://github.com/rpominov/static-land))
- [static land](https://github.com/rpominov/static-land) compatible

The idea (faking higher kinded types in Flow) is based on the paper [Lightweight higher-kinded polymorphism](https://www.cl.cam.ac.uk/~jdy22/papers/lightweight-higher-kinded-polymorphism.pdf) and [elm-brands](https://github.com/joneshf/elm-brands).

# Try it out

```
git clone https://github.com/gcanti/flow-static-land.git
cd flow-static-land
npm install
npm start
# execute ./node_modules/.bin/babel-node playground/index.js
# or open the page playground/index.html in a browser
# then edit playground/index.js
```

# Examples

Real world examples

- a Signal library ([purescript-signal](https://github.com/bodil/purescript-signal) porting)
- a QuickCheck library ([purescript-quickcheck](https://github.com/purescript/purescript-quickcheck) partial porting)

## `Maybe` and `Arr`
# Example

```js
import * as maybe from 'flow-static-land/Maybe'
import * as arr from 'flow-static-land/Arr'
import * as maybe from 'flow-static-land/lib/Maybe'
import * as arr from 'flow-static-land/lib/Arr'

const f = (n) => n * 2
const g = (n) => n + 1
Expand Down Expand Up @@ -63,47 +43,28 @@ const f = (n) => n * 2
^^^^^ number
```

## Expressing side effects with the `Eff` monad
# Related blog posts

See this [blog post](https://medium.com/@gcanti/the-eff-monad-implemented-in-flow-40803670c3eb#.sj4m00hpe) for context

```js
import type { Eff } from 'flow-static-land/Eff'
import { inj } from 'flow-static-land/Eff'
- [Higher kinded types with Flow](https://medium.com/@gcanti/higher-kinded-types-in-flow-275b657992b7)
- [Expressing side effects with the `Eff` monad](https://medium.com/@gcanti/the-eff-monad-implemented-in-flow-40803670c3eb)
- [Phantom types with Flow](https://medium.com/@gcanti/phantom-types-with-flow-828aff73232b)
- [Refinements with Flow](https://medium.com/@gcanti/refinements-with-flow-9c7eeae8478b)

class DB {}
# More examples

type User = {
username: string,
uid: number
};

const users = {}
let uid = 0

function createUser(username: string): Eff<{ write: DB }, User> {
return inj(() => {
users[username] = { username, uid: ++uid }
return users[username]
})
}
`examples` directory:

function lookupUser(username: string): Eff<{ read: DB }, ?User> {
return inj(() => users[username])
}

// the signature shows that createThenLookupUser will read and write to the db
const createThenLookupUser: (username: string) => Eff<{ read: DB, write: DB }, ?User> =
username => chain(user => lookupUser(user.username), createUser(username))
```
- a Signal library ([purescript-signal](https://github.com/bodil/purescript-signal) porting)
- a QuickCheck library ([purescript-quickcheck](https://github.com/purescript/purescript-quickcheck) partial porting)
- a React library (experimental)

# Setup

Download the source code with the command `npm i gcanti/flow-static-land#master`
**Bundles**
```sh
npm install flow-static-land --save
```

In order to build a bundle, add the following plugins to your `.babelrc` file
Babel config

```
{
Expand All @@ -116,15 +77,6 @@ In order to build a bundle, add the following plugins to your `.babelrc` file
}
```

For webpack, add the following include to your babel loader
```js
{
loader: 'babel',
include: [
path.resolve(__dirname, "node_modules/flow-static-land"),
path.resolve(__dirname, "path/to/your/code")
]
}
```
# License

The MIT License (MIT)
28 changes: 14 additions & 14 deletions QuickCheck.js → examples/QuickCheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
*/

import type { Eff } from './Eff'
import * as eff from './Eff'
import { CONSOLE } from './Console'
import { RANDOM, random } from './Random'
import { EXCEPTION, throwException, error } from './Exception'
import type { State } from './State'
import * as state from './State'
import type { Arr } from './Arr'
import * as arr from './Arr'
import { log } from './Console'
import type { Either } from './Either'
import * as either from './Either'
import { replicateA } from './Unfoldable'
import * as tuple from './Tuple'
import type { Eff } from '../src/Eff'
import * as eff from '../src/Eff'
import { CONSOLE } from '../src/Console'
import { RANDOM, random } from '../src/Random'
import { EXCEPTION, throwException, error } from '../src/Exception'
import type { State } from '../src/State'
import * as state from '../src/State'
import type { Arr } from '../src/Arr'
import * as arr from '../src/Arr'
import { log } from '../src/Console'
import type { Either } from '../src/Either'
import * as either from '../src/Either'
import { replicateA } from '../src/Unfoldable'
import * as tuple from '../src/Tuple'

/*
Expand Down
8 changes: 4 additions & 4 deletions React.js → examples/React.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// @flow
import { HKT } from './HKT'
import type { Contravariant } from './Contravariant'
import type { Arr } from './Arr'
import * as arr from './Arr'
import { HKT } from '../src/HKT'
import type { Contravariant } from '../src/Contravariant'
import type { Arr } from '../src/Arr'
import * as arr from '../src/Arr'
import React from 'react'

class IsReactComponent {}
Expand Down
20 changes: 10 additions & 10 deletions Signal.js → examples/Signal.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
*/

import type { Applicative } from './Applicative'
import type { Functor } from './Functor'
import type { Semigroup } from './Semigroup'
import type { Foldable } from './Foldable'
import type { Maybe } from './Maybe'
import type { Setoid } from './Setoid'
import type { Predicate } from './Fun'

import { HKT } from './HKT'
import * as maybe from './Maybe'
import type { Applicative } from '../src/Applicative'
import type { Functor } from '../src/Functor'
import type { Semigroup } from '../src/Semigroup'
import type { Foldable } from '../src/Foldable'
import type { Maybe } from '../src/Maybe'
import type { Setoid } from '../src/Setoid'
import type { Predicate } from '../src/Fun'

import { HKT } from '../src/HKT'
import * as maybe from '../src/Maybe'

class IsSignal {}

Expand Down
4 changes: 2 additions & 2 deletions exercises/answer1.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow

import type { Ord } from '../Ord'
import { numberOrd, stringOrd } from '../Ord'
import type { Ord } from '../src/Ord'
import { numberOrd, stringOrd } from '../src/Ord'

export function binarySearch<A>(xs: Array<A>, x: A, ord: Ord<A>): number {
function go(low: number, mid: number, high: number): number {
Expand Down
4 changes: 2 additions & 2 deletions exercises/answer2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow

import type { Ord } from '../Ord'
import { greaterThan, numberOrd } from '../Ord'
import type { Ord } from '../src/Ord'
import { greaterThan, numberOrd } from '../src/Ord'

export function isSorted<A>(xs: Array<A>, ord: Ord<A>): boolean {
const len = xs.length
Expand Down
4 changes: 2 additions & 2 deletions exercises/answer3.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow

import { HKT } from '../HKT'
import type { Functor } from '../Functor'
import { HKT } from '../src/HKT'
import type { Functor } from '../src/Functor'

class IsList {}

Expand Down
8 changes: 4 additions & 4 deletions exercises/answer4.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow

import type { Maybe } from '../Maybe'
import * as maybe from '../Maybe'
import type { Maybe } from '../src/Maybe'
import * as maybe from '../src/Maybe'

export function head<A>(xs: Array<A>): Maybe<A> {
if (xs.length) {
Expand All @@ -13,8 +13,8 @@ export function head<A>(xs: Array<A>): Maybe<A> {
console.log(head([1, 2, 3])) // => 1
console.log(head([])) // => null

import type { Either } from '../Either'
import * as either from '../Either'
import type { Either } from '../src/Either'
import * as either from '../src/Either'

export function elementAt<A>(xs: Array<A>, i: number): Either<string, A> {
if (i < 0) {
Expand Down
8 changes: 4 additions & 4 deletions exercises/answer5.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// @flow

import type { Maybe } from '../Maybe'
import * as maybe from '../Maybe'
import type { Maybe } from '../src/Maybe'
import * as maybe from '../src/Maybe'

import type { Arr } from '../Arr'
import * as arr from '../Arr'
import type { Arr } from '../src/Arr'
import * as arr from '../src/Arr'

export function getAllJustsOrNothing<A>(xs: Arr<Maybe<A>>): Maybe<Arr<A>> {
return arr.sequence(maybe, xs)
Expand Down
8 changes: 4 additions & 4 deletions exercises/answer6.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// @flow

import type { Arr } from '../Arr'
import * as arr from '../Arr'
import * as maybe from '../Maybe'
import * as tuple from '../Tuple'
import type { Arr } from '../src/Arr'
import * as arr from '../src/Arr'
import * as maybe from '../src/Maybe'
import * as tuple from '../src/Tuple'

export function evens(count: number): Arr<number> {
return arr.unfoldr(n => {
Expand Down
2 changes: 1 addition & 1 deletion exercises/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import type { Ord } from '../Ord'
import type { Ord } from '../src/Ord'

export function isSorted<A>(xs: Array<A>, ord: Ord<A>): boolean {
throw 'not implemented'
Expand Down
4 changes: 2 additions & 2 deletions exercises/exercise4.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Write a type safe head function.
*/
import type { Maybe } from '../Maybe'
import type { Maybe } from '../src/Maybe'

export function head<A>(xs: Array<A>): Maybe<A> {
throw 'not implemented'
Expand All @@ -18,7 +18,7 @@ export function head<A>(xs: Array<A>): Maybe<A> {
Write a type safe elementAt function
*/
import type { Either } from '../Either'
import type { Either } from '../src/Either'

export function elementAt<A>(xs: Array<A>, i: number): Either<string, A> {
throw 'not implemented'
Expand Down
4 changes: 2 additions & 2 deletions exercises/exercise5.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
Just with a list of all the values
*/
import type { Arr } from '../Arr'
import type { Maybe } from '../Maybe'
import type { Arr } from '../src/Arr'
import type { Maybe } from '../src/Maybe'

export function getAllJustsOrNothing<A>(xs: Arr<Maybe<A>>): Maybe<Arr<A>> {
throw 'not implemented'
Expand Down
2 changes: 1 addition & 1 deletion exercises/exercise6.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Hint: use arr.unfoldr
*/
import type { Arr } from '../Arr'
import type { Arr } from '../src/Arr'

export function evens(count: number): Arr<number> {
throw 'not implemented'
Expand Down
Loading

0 comments on commit 6f6bfea

Please sign in to comment.