This file contains 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 Intro where | |
import Control.Arrow ((&&&)) | |
newtype Term f = | |
In { out :: f (Term f) } | |
type Algebra f a = f a -> a | |
cata :: (Functor f) => Algebra f a -> Term f -> a |
This file contains 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 TupleSections #-} | |
module PopLens where | |
data IStore a b t = IStore a (b -> t) | |
deriving (Functor) | |
type Lens s t a b = s -> IStore a b t |
This file contains 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 FlexibleContexts #-} | |
import Control.Monad.State.Lazy | |
import Data.Map hiding (map, splitAt) | |
import Prelude hiding (lookup) | |
memoize2 f p@(x, _) = do -- only uses 1st arg as key | |
v <- gets $ lookup x | |
case v of | |
Just y -> return y |
This file contains 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 FlexibleContexts #-} | |
import Control.Monad.Identity | |
import Control.Monad.State.Lazy | |
import Data.Map | |
import Prelude hiding (lookup) | |
memoize :: (MonadState (Map k a) m, Ord k) => | |
(k -> m a) -> k -> m a | |
memoize f x = do |
This file contains 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 RankNTypes #-} | |
data Ex = forall a. Ex a | |
type State i o a = i -> (a, o) | |
-- enforce independence of types i and a: | |
newtype Filt a = Filt { unFilt :: forall i. i -> (a, Ex) } |
This file contains 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
mkChart :: (Eq cat, Eq term) => | |
CFG cat term -> [term] -> [((Int, Int), [cat])] | |
mkChart g xs = helper (0,1) [] where | |
helper p@(i,j) tab | |
| j>length xs = tab | |
| i<0 = helper (j,j+1) tab | |
| i==j-1 = helper (i-1,j) $ | |
(p, [n | n:-t <- g, t==xs!!(j-1)]):tab | |
| otherwise = helper (i-1,j) $ | |
(p, [n | n:>(l,r) <- g, k <- [i+1..j-1], |
This file contains 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 Data.Tree | |
splitsPlus :: [a] -> [([a], [a])] | |
splitsPlus u = [splitAt i u | i <- [1..length u - 1]] | |
data Rule n x = n :- x | n :< (n, n) | |
deriving (Eq, Show) | |
parse | |
:: (Eq cat, Eq term) => |
This file contains 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 OverloadedStrings #-} | |
module Re ( | |
Re, | |
(<>), (<+>), star, zero, one, neg, | |
nullable, derive, mkDfa, minimize, | |
anyc, alpha, lower, upper, digit | |
) where | |
import Data.Char |
This file contains 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 OverloadedStrings #-} | |
module Regexp ( | |
Regexp, | |
(<+>), (<>), star, zero, | |
match, anyc | |
) where | |
import Data.Char | |
import GHC.Exts (IsString (..)) |
This file contains 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 Markov where | |
import qualified Control.Monad.Random as R | |
import qualified Data.Map as M | |
import Utils | |
type Hist = [String] -- prior context as list of words | |
type Next = String | |
type Ngrams = [(Hist, Next)] |
NewerOlder