packages feed

reflection-without-remorse (empty) → 0.9

raw patch · 6 files changed

+134/−0 lines, 6 filesdep +basedep +type-alignedsetup-changed

Dependencies added: base, type-aligned

Files

+ ChangeLog view
@@ -0,0 +1,2 @@++0.9: Initial version
+ Control/Monad/Free/Reflectable.hs view
@@ -0,0 +1,47 @@+{-# LANGUAGE ExistentialQuantification,GADTs #-}++-----------------------------------------------------------------------------+-- |+-- Module      :  Control.Monad.Free.Reflectable+-- Copyright   :  (c) Atze van der Ploeg 2014+-- License     :  BSD-style+-- Maintainer  :  atzeus@gmail.org+-- Stability   :  provisional+-- Portability :  portable+-- A free monad that supports alternating between building and observing.+-- It supports all operatorions ('>>=', 'return', 'fromView' and 'toView') in worst case constant time.+--+-- See the paper Reflection without Remorse: Revealing a hidden sequence to speed up Monadic Reflection, Atze van der Ploeg and Oleg Kiselyov, Haskell Symposium 2014+-- for more details.+--+-- Paper: <http://homepages.cwi.nl/~ploeg/zseq.pdf>+-- Talk : <http://www.youtube.com/watch?v=_XoI65Rxmss>+-----------------------------------------------------------------------------++module Control.Monad.Free.Reflectable(FreeMonadView(..),FreeMonad, fromView,toView) where++import Data.TASequence.FastCatQueue++newtype FC f a b = FC (a -> FreeMonad f b)+type FMExp f a b = FastTCQueue (FC f) a b+data FreeMonad f a = +   forall x. FM (FreeMonadView f x) (FMExp f x a)+data FreeMonadView f a 	= Pure a +                        | Impure (f (FreeMonad f a))+fromView x = FM x tempty++toView :: Functor f => FreeMonad f a -> FreeMonadView f a+toView (FM h t) = case h of+   Pure x -> +    case tviewl t of+       TAEmptyL -> Pure x+       FC hc :< tc -> toView (hc x >>>= tc)+   Impure f -> Impure (fmap (>>>= t) f) + where (>>>=) :: FreeMonad f a -> FMExp f a b -> FreeMonad f b +       (FM h t) >>>= r = FM h (t >< r)++instance Monad (FreeMonad f) where+  return = fromView . Pure+  (FM m r) >>= f = FM m (r >< tsingleton (FC f))++
+ Control/Monad/Operational/Reflectable.hs view
@@ -0,0 +1,49 @@+{-# LANGUAGE ExistentialQuantification,GADTs #-}+++-----------------------------------------------------------------------------+-- |+-- Module      :  Control.Monad.Operational.Reflectable+-- Copyright   :  (c) Atze van der Ploeg 2014+-- License     :  BSD-style+-- Maintainer  :  atzeus@gmail.org+-- Stability   :  provisional+-- Portability :  portable+-- An operational monad that supports alternating between building and observing.+-- It supports all operatorions ('>>=', 'return', 'fromView' and 'toView') in worst case constant time.+--+-- See the paper Reflection without Remorse: Revealing a hidden sequence to speed up Monadic Reflection, Atze van der Ploeg and Oleg Kiselyov, Haskell Symposium 2014+-- for more details.+--+-- Paper: <http://homepages.cwi.nl/~ploeg/zseq.pdf>+-- Talk : <http://www.youtube.com/watch?v=_XoI65Rxmss>+-----------------------------------------------------------------------------++module Control.Monad.Operational.Reflectable(Program,ProgramView(..), fromView, toView) where++import Data.TASequence.FastCatQueue++newtype TermMCont r a b = TC (a -> Program r b)+type TermCExp r a b = FastTCQueue (TermMCont r) a b++data ProgramView r a where+  Bind   :: r w -> (w -> Program r a) -> ProgramView r a+  Return :: a -> ProgramView r a++data Program r a = forall x. Program (ProgramView r x) (TermCExp r x a)++fromView :: ProgramView r a -> Program r a+fromView r = Program r tempty++toView :: Program r a -> ProgramView r a+toView (Program x s) = case x of+  Return a -> case tviewl s of +             TAEmptyL -> Return a+             TC h :< t  -> toView $ (h a) <.|| t+  Bind t f -> Bind t (\x -> f x <.|| s) +  where (<.||) :: Program r a -> TermCExp r a b -> Program r b+        (Program x l) <.|| r = Program x (l >< r)++instance Monad (Program r) where+  return = fromView . Return+  (Program t s) >>= f = Program t (s |> TC f)
+ LICENSE view
@@ -0,0 +1,11 @@+Copyright (c) 2014, Atze van der Ploeg+All rights reserved.++Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:++1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.++2. 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.++3. Neither the name of the Atze van der Ploeg nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.+
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ reflection-without-remorse.cabal view
@@ -0,0 +1,23 @@+Name:                reflection-without-remorse+Version:             0.9+Synopsis:	         Efficient free and operational monads. +Description:         Free and operational monads that efficiently support alternating between building and observing.+License:             BSD3+License-file:        LICENSE+Author:              Atze van der Ploeg+Maintainer:          atzeus@gmail.com+Homepage:            https://github.com/atzeus/reflection-without-remorse+Build-Type:          Simple+Cabal-Version:       >=1.6+Data-files:          ChangeLog+Category:            Data, Data Structures+Tested-With:         GHC==7.6.3+Library+  Build-Depends: base >= 2 && <= 6, type-aligned+  Exposed-modules: Control.Monad.Free.Reflectable, Control.Monad.Operational.Reflectable++  Extensions:	 GADTs, TypeSynonymInstances,FlexibleInstances, ViewPatterns, TypeOperators++source-repository head+    type:     git+    location:  https://github.com/atzeus/reflection-without-remorse