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 GeneralizedNewtypeDeriving #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE ExistentialQuantification #-} | |
{-# LANGUAGE MultiWayIf #-} | |
module Transducer (GenericTDAction, TDAction, StateTDAction, | |
Transducer, stop, transducer, stateTransducer, writeState, | |
readState, returnStream, Transducer.map, Transducer.filter, | |
Transducer.take, Transducer.cat, Transducer.mapcat, | |
Transducer.remove, Transducer.takeWhile, Transducer.takeNth, | |
Transducer.drop, Transducer.dropWhile) 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
(define string-parser | |
(let* ((escaped-char (effect (run parse-char #\\) | |
(run any-char))) | |
(string-char (alternative (none-of '(#\" #\\)) | |
escaped-char)) | |
(parse-quote (parse-char #\"))) | |
(effect | |
(let* ((_ (run parse-quote)) | |
(chars (run many string-char)) | |
(_ (run parse-quote))) |
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 DataKinds #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
module AesonTrans ( | |
AesonTrans, fromField, maybeFromField, preTransJSON, postTransJSON, | |
transFieldModifier) | |
where | |
import Data.Aeson | |
import Data.Aeson.Types |
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
grinMain = x <- readList 10 | |
x' <- store x | |
y <- deltaOfDelta x' | |
y' <- store y | |
printAll y' | |
readList n = | |
b <- _prim_int_gt n 0 | |
if b then | |
s <- _prim_read_string |
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 GeneralizedNewtypeDeriving #-} | |
{-# LANGUAGE LambdaCase #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE ScopedTypeVariables#-} | |
{-# LANGUAGE FlexibleContexts #-} | |
module Text.XML.Expat.Tree.Parser where | |
import Data.Bifunctor | |
import Control.Monad.Trans (lift) | |
import Control.Monad.State hiding (fail, lift) | |
import Control.Applicative hiding (many) |
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 DeriveGeneric #-} | |
{-# LANGUAGE StandaloneDeriving #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE TemplateHaskell #-} | |
{-# LANGUAGE KindSignatures #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
module Test where | |
import GHC.Generics | |
import Unbound.Generics.LocallyNameless |
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
class GToHttpApiData a where | |
gToQueryParam :: (String -> String) -> a f -> Text | |
instance GToHttpApiData b => GToHttpApiData (D1 m b) where | |
gToQueryParam pref (M1 x) = gToQueryParam pref x | |
instance (GToHttpApiData (a f), GToHttpApiData (b f)) | |
=> GToHttpApiData (a f :+: b f) where | |
gToQueryParam pref (L1 a) = gToQueryParam pref a |
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 DataKinds #-} | |
module Test where | |
import Data.TypeRepMap | |
data Currency = USD | EUR | JPY | |
-- | A typesafe money datatype, indexed by currency | |
newtype Money (a :: Currency) = Money Int | |
-- | A datatype to hide the currency information, using existential quantification | |
data SomeMoney = forall (a :: Currency) . SomeMoney {getMoney :: Money a } |
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 TypeFamilies #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
{-# LANGUAGE RankNTypes #-} | |
module UnwrapIO where | |
import Control.Monad | |
import Control.Monad.Trans | |
import Control.Monad.Trans.State | |
import Control.Monad.Trans.Except | |
import Control.Monad.Trans.Maybe | |
import Control.Monad.Trans.Reader |
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 ScopedTypeVariables #-} | |
module Sums where | |
import Data.IntMap.Lazy (IntMap) | |
import Data.Maybe | |
import Data.Monoid ((<>)) | |
import qualified Data.IntMap as IntMap | |
-- find all subsets which add upto the given size, given a function to | |
-- extract the size. Only pick at most one element from each input subset. | |
sums :: forall a.(a -> Int) -> Int -> [[a]] -> [[a]] |