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 PolyKinds, DataKinds, GADTs, TypeOperators, ConstraintKinds, RankNTypes, MultiParamTypeClasses, FlexibleInstances, FlexibleContexts, UndecidableInstances #-} | |
import Data.Proxy | |
import Data.Functor.Identity | |
import GHC.Exts (Constraint) | |
data HKList :: (k -> *) -> [k] -> * where | |
Nil :: HKList f '[] | |
(:*) :: f x -> HKList f xs -> HKList f (x ': xs) | |
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 GADTs #-} | |
{-# Language DataKinds #-} | |
{-# Language KindSignatures #-} | |
{-# Language ViewPatterns #-} | |
{-# Language RankNTypes #-} | |
{-# Language ScopedTypeVariables #-} | |
import Control.Applicative |
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 #-} | |
{-# language FlexibleInstances #-} | |
import Data.Function | |
class Functor w => Comonad w where | |
extract :: w a -> a | |
duplicate :: w a -> w (w a) | |
kfix :: ComonadApply w => w (w a -> a) -> w 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
main = do | |
chars <- getLine | |
let otherchars = do | |
a <- chars | |
b <- chars | |
[a] ++ [b] | |
putStrLn otherchars |
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 DefaultSignatures #-} | |
{-# LANGUAGE TypeOperators #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE DeriveGeneric #-} -- Only needed for the DSL example | |
import GHC.Generics | |
-- Data types that are constant and uninteresting | |
class Eq a => Const 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 PolyKinds #-} | |
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE RankNTypes #-} | |
module Data.TypeMap ( | |
TypeMap (), | |
null, | |
size, | |
member, |
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
deleteLast :: (a -> Bool) -> [a] -> [a] | |
deleteLast delete = snd . go | |
where | |
go [] = (False, []) | |
go (x:xs) = (delete x || deleteLater, if not (delete x) || deleteLater then x:xs' else xs') | |
where | |
(deleteLater, xs') = go xs | |
filterLast p = deleteLast (not . p) |
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 Statistics.Distribution | |
import Statistics.Distribution.Normal | |
data D n = D {n :: n, s :: n} | |
instance Integral n => Distribution (D n) where | |
cumulative d x = cumulativeD d (floor x) | |
instance Integral n => DiscreteDistr (D n) where | |
probability d x = probabilityD d (fromIntegral x) |
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.Applicative | |
import Data.List | |
import Data.Maybe | |
data Term = Var Int | Lam Int Term | App Term Term deriving (Show) | |
data BTerm = BVar Int | BLam BTerm | BApp BTerm BTerm deriving (Show) -- BVar 0 refers to the closest lambda | |
lam2db :: Term -> Maybe BTerm | |
lam2db = go [] | |
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
module Control.PrimRec ( | |
ArrowLike (..), | |
PrimRec (..), | |
module Control.Category, | |
module Data.Nat | |
) where | |
import Control.Category | |
import Data.Nat |
NewerOlder