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 AllowAmbiguousTypes #-} | |
| {-# LANGUAGE BlockArguments #-} | |
| {-# LANGUAGE DataKinds #-} | |
| {-# LANGUAGE PartialTypeSignatures #-} | |
| {-# LANGUAGE TypeFamilies #-} | |
| module PLASafe where | |
| import Control.Monad (replicateM) | |
| import Data.Proxy (Proxy (..)) |
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 FlexibleInstances #-} | |
| module Main where | |
| import Data.Either (isRight) | |
| import Data.Foldable (foldl') | |
| import qualified Data.Map as M | |
| import qualified Data.Set as S | |
| -- Basic data and 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
| {-# LANGUAGE TypeFamilies #-} | |
| data S | |
| data DP | |
| data N | |
| data result :/ argument | |
| data argument :\ result | |
| class Symantics repr 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 Main where | |
| import Control.Monad (forM_, replicateM, replicateM_) | |
| import Control.Monad.Primitive (RealWorld) | |
| import Data.Array (Array, Ix (range), array, bounds, indices, (!)) | |
| import SpecShape (Grammar, allSymbols, convertToIdxGrammar, grammar, isTerm) | |
| import System.IO (IOMode (..), hPutStrLn, withFile) | |
| import System.Random.MWC | |
| ( Gen, | |
| Variate (uniformR), |
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, TypeFamilies #-} | |
| {-# OPTIONS -W #-} | |
| import Data.Maybe (fromJust) | |
| import Control.Applicative ((<|>)) | |
| -- parsing to untyped term | |
| data Sym = A | B | |
| deriving (Show, Eq) |
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 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 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 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 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 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 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 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 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 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) } |
NewerOlder