data-fresh (empty) → 0.2013.250
raw patch · 5 files changed
+113/−0 lines, 5 filesdep +basedep +transformerssetup-changed
Dependencies added: base, transformers
Files
- LICENSE +30/−0
- Setup.hs +2/−0
- data-fresh.cabal +23/−0
- src/Control/Monad/Trans/Fresh.hs +49/−0
- src/Data/Fresh.hs +9/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2013, Stijn van Drongelen++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Stijn van Drongelen nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ data-fresh.cabal view
@@ -0,0 +1,23 @@+name: data-fresh+version: 0.2013.250+stability: experimental+category: Control+synopsis: An interface for generating fresh values+license: BSD3+license-file: LICENSE+copyright: Copyright (c) 2013 Stijn van Drongelen+author: Stijn van Drongelen+maintainer: Stijn van Drongelen <rhymoid@gmail.com>+build-type: Simple+cabal-version: >=1.10++source-repository head+ type: git+ location: https://github.com/rhymoid/hs-data-fresh.git++library+ default-language: Haskell2010+ other-extensions: FlexibleInstances, MultiParamTypeClasses+ exposed-modules: Control.Monad.Trans.Fresh, Data.Fresh+ build-depends: base >= 4 && < 5, transformers >= 0.2 && < 1+ hs-source-dirs: src
+ src/Control/Monad/Trans/Fresh.hs view
@@ -0,0 +1,49 @@+{-# LANGUAGE Haskell2010 #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-}+module Control.Monad.Trans.Fresh where++import Control.Applicative+import Control.Arrow (first)+import Control.Monad.Trans.Class+import Data.Fresh+import Data.Functor.Identity++newtype FreshT v m a = FreshT { runFreshT :: (v -> (v, v)) -> v -> m (a, v) }++instance Functor m => Functor (FreshT v m) where+ fmap f (FreshT xx) = FreshT $ \sp s -> fmap (first f) (xx sp s)+ x <$ FreshT xx = FreshT $ \sp s -> fmap (setFst x) (xx sp s)+ where+ setFst :: b -> (a, c) -> (b, c)+ setFst x (_, y) = (x, y)++instance (Functor m, Monad m) => Applicative (FreshT v m) where+ pure = return+ FreshT ff <*> FreshT xx = FreshT $ \sp s -> do+ (fv, s1) <- ff sp s + (xv, s2) <- xx sp s1+ return (fv xv, s2)+ --FreshT ll *> FreshT rr = FreshT $ undefined+ --FreshT ll <* FreshT rr = FreshT $ undefined++instance Monad m => Monad (FreshT v m) where+ return x = FreshT $ \_ s -> return (x, s)+ FreshT aa >>= f = FreshT $ \sp s -> do+ (a, s1) <- aa sp s+ let FreshT ff = f a+ ff sp s1+ -- (>>) = (*>)++-- TODO Alternative, MonadPlus+-- TODO MonadFix++instance MonadTrans (FreshT v) where+ lift m = FreshT $ \_ s -> do+ r <- m+ return (r, s)++-- TODO MonadIO++instance Applicative m => Fresh v (FreshT v m) where+ fresh = FreshT $ \sp s -> pure (sp s)
+ src/Data/Fresh.hs view
@@ -0,0 +1,9 @@+{-# LANGUAGE Haskell2010 #-}+{-# LANGUAGE MultiParamTypeClasses #-}+module Data.Fresh+ ( Fresh (..)+ ) where++class Fresh v m where+ -- TODO Laws.+ fresh :: m v