This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main (main) where | |
import Control.Monad (void) | |
import Control.Monad.Identity | |
import Criterion.Main | |
import qualified Data.Conduit as C | |
import qualified Data.Conduit.Combinators as CC | |
import qualified Data.Conduit.List as C | |
import qualified Data.Machine as M | |
import qualified Data.Machine.Fanout as BenS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad.Trans.State.Strict | |
import Control.Monad.Trans.Class | |
import Test.Tasty (TestTree, defaultMain, testGroup) | |
import Test.Tasty.QuickCheck (testProperty) | |
import Test.QuickCheck | |
import Data.Machine | |
import Data.Machine.Fanout | |
import Data.Machine.Lift |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Control.Monad.Free | |
data StackF a | |
= Push Int a | |
| Pop (Int -> a) | |
instance Functor StackF where | |
fmap f (Push x k) = Push x (f k) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE ExistentialQuantification #-} | |
{-# LANGUAGE Rank2Types #-} | |
module Unfold where | |
import Control.Applicative | |
import Data.List | |
data Fold a b = forall x . Fold (x -> a -> x) x (x -> b) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE KindSignatures #-} | |
{-# LANGUAGE ConstraintKinds #-} | |
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | |
import Control.Category | |
import GHC.Exts (Constraint) | |
import Prelude hiding ((.)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# OPTIONS --termination-depth=2 #-} | |
module Printf where | |
open import Algebra.FunctionProperties using (Associative) | |
open import Data.Char using (Char) renaming (_≟_ to _≟ᶜ_) | |
open import Data.List using (List; []; _∷_; [_]; length) | |
open import Data.Maybe | |
open import Data.Nat using (ℕ; suc) | |
open import Data.Nat.Show using (show) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MonadLaws where | |
open import Category.Applicative | |
open import Category.Applicative.Indexed | |
open import Category.Functor | |
open import Category.Monad | |
open import Category.Monad.Indexed | |
open import Data.Maybe renaming (monad to monadMaybe) | |
open import Function | |
open import Level |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Decide if applying f over a collection gives either Nothing or Just for every element. | |
decideMaybes :: Traversable f => (a -> Maybe b) -> f a -> Maybe (Either (f a) (f (a, b))) | |
decideMaybes f xs = | |
asum [Left <$> nothingsOf pairs, Right <$> justsOf pairs, Nothing] | |
where | |
pairs = fmap (\x -> (x, f x)) xs | |
nothingsOf = traverse (\(x,y) -> x <$ guard (isNothing y)) | |
justsOf = traverse (\(x,y) -> (x, fromJust y) <$ guard (isJust y)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE EmptyDataDecls #-} | |
{-# LANGUAGE ForeignFunctionInterface #-} | |
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE RecordWildCards #-} | |
module Command | |
( Command, Root, User, Verbose | |
, runAsRoot, runAsCurrentUser | |
, command, getTempName, dropRoot | |
) where |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
runController :: (MonadIO m) => Controller a -> Producer a m () | |
runController (Controller m) = do | |
input <- liftIO m | |
let loop = do | |
xM <- liftIO (atomically $ recv input) | |
maybe (return ()) (\x -> yield x >> loop) xM | |
loop | |
type StateFn s = (Maybe s -> s) -> IO s |