Skip to content

Instantly share code, notes, and snippets.

{-# LANGUAGE FlexibleContexts , ScopedTypeVariables , TypeFamilies #-}
import Data.Proxy
class Problem p where
type State p :: *
data Action p :: *
actions :: State p -> [Action p]
result :: State p -> Action p -> State p
@echatav
echatav / Learn.hs
Last active January 27, 2018 00:11
{-# LANGUAGE ExistentialQuantification #-}
import Prelude hiding (id,(.))
import Control.Category
data Learn a b
= forall p. Learn
{ impl :: p -> a -> b
, update :: p -> a -> b -> p
, request :: p -> a -> b -> a
{-# LANGUAGE
DeriveAnyClass
, DeriveGeneric
, DerivingStrategies
, GADTs
, LambdaCase
, OverloadedStrings
#-}
module Migratory where
module Data.Distributor
( -- * lax monoidal profunctors
Monoidal (unit, (>*<)) , dimap2, (>*), (*<)
, replicateP, replicateP_, foreverP
, Mon (Mon), liftMon
-- * lax distributors
, Distributor (zero, (>+<), several, several1, possibly)
, dialt, (>|<)
, Dist (DistEmpty, DistEither)
, DistAlt (DistAlts), liftDistAlt
newtype Grammar a b = Grammar
(Loop (String := Production) () (Production a b))
type Production = DistAlt (ChooseMon (Token Char Char))
newtype Loop p a b = Loop
{ runLoop
:: forall q. ArrowLoop q
=> (forall x y. p x y -> q x y)
-> q a b
@echatav
echatav / distributive
Last active April 21, 2024 15:41
alternative and distributive functors and profunctors
Given distributive category
* -C>, >C<, 1C, +C+, 0C
And monoidal category
* -D>, >D<, 1D
A lax alternative functor consists of
* A functor
- F : C -> D
* morphisms
- eps : 1D -D> F(1C)
- mu : F(a) >D< F(b) -D> F(a >C< b)
@echatav
echatav / Trans.hs
Last active February 12, 2024 01:42
Haskell Constraint Adjoint
module Constraint.Trans where
class (forall a. c a => d (f a))
=> CFunctor c d f | f -> c, f -> d where
-- prop> cmap id = id
-- prop> cmap (g . f) = cmap g . cmap f
cmap :: (c a, c b) => (a -> b) -> f a -> f b
class CFunctor c d f
=> CTrans c d f where