Skip to content

Instantly share code, notes, and snippets.

View schar's full-sized avatar
💭
🦧

Simon Charlow schar

💭
🦧
View GitHub Profile
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE TypeFamilies #-}
module PLASafe where
import Control.Monad (replicateM)
import Data.Proxy (Proxy (..))
@schar
schar / EDPL.hs
Last active March 29, 2026 16:35
{-# 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
@schar
schar / Apply.hs
Last active March 24, 2026 11:56
{-# LANGUAGE TypeFamilies #-}
data S
data DP
data N
data result :/ argument
data argument :\ result
class Symantics repr where
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),
@schar
schar / TTFCC.hs
Last active March 24, 2026 11:58
{-# LANGUAGE GADTs, TypeFamilies #-}
{-# OPTIONS -W #-}
import Data.Maybe (fromJust)
import Control.Applicative ((<|>))
-- parsing to untyped term
data Sym = A | B
deriving (Show, Eq)
@schar
schar / HistoFib.hs
Last active November 4, 2022 19:08
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
@schar
schar / PopLens.hs
Last active October 24, 2022 17:09
{-# 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
{-# 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
@schar
schar / Memo.hs
Created June 11, 2022 00:26
Haskell memoization monadically
{-# 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
@schar
schar / Ex.hs
Created December 12, 2021 03:20
{-# 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) }