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 MultiParamTypeClasses, FlexibleInstances, FlexibleContexts #-} | |
module Subtype where | |
data Derived super sub = Derived super sub | |
class IsInstance b a where | |
getData :: (a -> v) -> b -> v | |
setData :: (a -> s -> s) -> b -> s -> s | |
instance IsInstance (Derived a b) a 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
{-# LANGUAGE TypeFamilies, FlexibleContexts #-} | |
module ChessVariant where | |
import Data.Proxy | |
data Square = Square Int Int Int | |
newtype Side = Side Int | |
data Piece variant = Piece (PieceType variant) Side | |
data MoveStep variant = |
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 DataKinds, KindSignatures, TypeOperators, TypeFamilies, GADTs, | |
MultiParamTypeClasses, FunctionalDependencies, ExplicitForAll, | |
FlexibleInstances, FlexibleContexts, UndecidableInstances, | |
ScopedTypeVariables, TypeApplications | |
#-} | |
module Fossa where | |
import GHC.TypeLits | |
import Data.Proxy | |
-- Determine if s matches the symbol in the first tuple of the type |
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 SimpleParser where | |
import Text.Parsec | |
import Data.Text as T | |
import Data.Char | |
type SimpleParser a b = Parsec [a] () b | |
parseMaybe :: Show a => (a -> Maybe b) -> SimpleParser a b | |
parseMaybe f = tokenPrim show (\s _ _ -> incSourceColumn s (sourceColumn s)) f |
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 RankNTypes #-} | |
module Test where | |
type MyType a = forall m. Monad m => m a | |
test :: MyType Int | |
test = pure 3 | |
x :: IO Int | |
x = test |
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 DeriveFunctor #-} | |
module Test where | |
import Data.Functor.Foldable | |
import Control.Monad.Free | |
import qualified Control.Monad.Trans.Free as T | |
data Tree t = Tree t t | |
deriving Functor |
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
-- this is the same as Functor fmap, but that instance cannot be | |
-- written, since the type variable is one level too deep. | |
fixmap :: (Functor (f a), Bifunctor f) => (a -> b) -> Fix (f a) -> Fix (f b) | |
fixmap f = cata (Rec . first f) |
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 LinkGraph where | |
import Data.IntMap | |
import Data.Function | |
import Data.Maybe | |
import Prelude hiding (lookup) | |
data Fix f = Rec { unRec :: f (Fix f)} | |
unsafeLinkGraph :: Functor f => IntMap (f Int) -> IntMap (Fix f) | |
unsafeLinkGraph g = |
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
data Sum = Plus Sum Sum | |
| Lit Integer | |
| Var String | |
deriving Show | |
simplify :: Sum -> Sum | |
simplify (Var a) = Var a | |
simplify (Lit a) = Lit a | |
simplify (Plus (Lit 0) a) = simplify a | |
simplify (Plus a (Lit 0)) = simplify 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 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]] |