diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..68528b0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2014 PureScript + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), 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. diff --git a/MODULE.md b/MODULE.md new file mode 100644 index 0000000..de59341 --- /dev/null +++ b/MODULE.md @@ -0,0 +1,21 @@ +# Module Documentation + +## Module Data.Inject + +### Type Classes + + class Inject f g where + inj :: forall a. f a -> g a + prj :: forall a. g a -> Maybe (f a) + + +### Type Class Instances + + instance injectLeft :: Inject f (Coproduct f g) + + instance injectReflexive :: Inject f f + + instance injectRight :: (Inject f g) => Inject f (Coproduct h g) + + + diff --git a/README.md b/README.md new file mode 100644 index 0000000..97e54d2 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# purescript-inject diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..b709e0c --- /dev/null +++ b/bower.json @@ -0,0 +1,21 @@ +{ + "name": "purescript-inject", + "homepage": "https://github.com/purescript-contrib/purescript-inject", + "description": "Inject typeclass", + "keywords": [ + "purescript" + ], + "license": "MIT", + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "examples", + "dist" + ], + "dependencies": { + "purescript-coproducts": "0.1.0", + "purescript-either": "0.1.4", + "purescript-maybe": "0.2.1" + } +} diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..7c714f5 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,63 @@ +var gulp = require('gulp') + , gutil = require('gulp-util') + , plumber = require('gulp-plumber') + , purescript = require('gulp-purescript') + , sequence = require('run-sequence') + , del = require('del') + , config = { + del: ['dist'], + purescript: { + src: [ + 'bower_components/purescript-*/src/**/*.purs*', + 'src/**/*.purs' + ], + dest: 'dist', + docs: 'MODULE.md' + } + } +; + +function error(e) { + gutil.log(gutil.colors.magenta('>>>> Error <<<<') + '\n' + e.toString().trim()); + this.emit('end'); +} + +gulp.task('del', function(cb){ + del(config.del, cb); +}); + +gulp.task('make', function(){ + return ( + gulp.src(config.purescript.src). + pipe(plumber()). + pipe(purescript.pscMake({output: config.purescript.dest})). + on('error', error) + ); +}); + +gulp.task('psci', function(){ + return ( + gulp.src(config.purescript.src). + pipe(plumber()). + pipe(purescript.dotPsci()). + on('error', error) + ); +}); + +gulp.task('docs', function(){ + return ( + gulp.src(config.purescript.src[1]). + pipe(plumber()). + pipe(purescript.pscDocs()). + on('error', error). + pipe(gulp.dest(config.purescript.docs)) + ); +}); + +gulp.task('watch', function(cb){ + gulp.watch(config.purescript.src, ['make']); +}); + +gulp.task('default', function(){ + sequence('del', 'make', ['psci', 'docs']); +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..035252b --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "name": "purescript-inject", + "private": true, + "devDependencies": { + "del": "0.1.3", + "gulp": "3.8.10", + "gulp-plumber": "0.5.6", + "gulp-purescript": "0.1.2", + "gulp-util": "2.2.14", + "run-sequence": "0.3.6" + } +} diff --git a/src/Data/Inject.purs b/src/Data/Inject.purs new file mode 100644 index 0000000..6edb178 --- /dev/null +++ b/src/Data/Inject.purs @@ -0,0 +1,24 @@ +module Data.Inject + ( Inject + , inj, prj + ) where + +import Data.Either (Either(..)) +import Data.Functor.Coproduct (Coproduct(..), coproduct) +import Data.Maybe (Maybe(..)) + +class Inject f g where + inj :: forall a. f a -> g a + prj :: forall a. g a -> Maybe (f a) + +instance injectReflexive :: Inject f f where + inj = id + prj = Just + +instance injectLeft :: Inject f (Coproduct f g) where + inj = Coproduct <<< Left + prj = coproduct Just (const Nothing) + +instance injectRight :: (Inject f g) => Inject f (Coproduct h g) where + inj = Coproduct <<< Right <<< inj + prj = coproduct (const Nothing) prj