Skip to content

Instantly share code, notes, and snippets.

@sjoerdvisscher
sjoerdvisscher / OpenStarSemiring.lhs
Created Jun 14, 2020
Playing with 'A Very General Method of Computing Shortest Paths'
View OpenStarSemiring.lhs
This is an extension of "A Very General Method of Computing Shortest Paths" to use "open matrices".
This is from a paper "The Open Algebraic Path Problem" by Jade Master https://arxiv.org/abs/2005.06682
> {-# LANGUAGE TypeFamilies #-}
> {-# LANGUAGE TypeApplications #-}
> {-# LANGUAGE FlexibleContexts #-}
> {-# LANGUAGE StandaloneDeriving #-}
> {-# LANGUAGE AllowAmbiguousTypes #-}
> {-# LANGUAGE ScopedTypeVariables #-}
> module OpenStarSemiring where
@sjoerdvisscher
sjoerdvisscher / DistT.hs
Last active Jun 6, 2020
A distribution monad transformer
View DistT.hs
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE RankNTypes #-}
module Control.Monad.Trans.DistT where
import Data.List.NonEmpty (NonEmpty(..))
import Control.Monad.Trans.Class
import Control.Monad.Trans.Free
import Control.Arrow (Arrow(first))
import Control.Applicative (liftA2, Alternative(..))
@sjoerdvisscher
sjoerdvisscher / nucleus.hs
Created Apr 17, 2020
Nucleus of a profunctor
View nucleus.hs
{-# LANGUAGE
PolyKinds
, RankNTypes
, TypeFamilies
, TypeOperators
, TypeApplications
, FlexibleInstances
, ScopedTypeVariables
, AllowAmbiguousTypes
, MultiParamTypeClasses
@sjoerdvisscher
sjoerdvisscher / Cotra.hs
Created Nov 28, 2019
Cofree traversable functor
View Cotra.hs
{-# LANGUAGE GADTs #-}
import Data.Functor.HCofree
import Data.Vec.Lazy
import Data.Fin
import Data.Type.Nat
data Cotra f a where
Cotra :: SNat n -> f (Fin n) -> Vec n a -> Cotra f a
to :: Functor f => Cotra f a -> HCofree Traversable f a
@sjoerdvisscher
sjoerdvisscher / moorelens.hs
Last active Dec 5, 2019
Moore machines as lenses
View moorelens.hs
{-# LANGUAGE ScopedTypeVariables, RankNTypes #-}
import Control.Lens -- from `lens`
import Control.Monad.State.Lazy
moore :: MonadState s m => Lens s s b a -> Traversal as bs a b -> as -> m bs
moore l trav = trav (\a -> l <<.= a)
runMoore :: Lens s s b a -> s -> [a] -> [b]
runMoore l s fa = evalState (moore l traverse fa) s
@sjoerdvisscher
sjoerdvisscher / 0. Equipment.hs
Last active May 10, 2020
Proarrow equipments
View 0. Equipment.hs
{-# LANGUAGE
GADTs
, DataKinds
, PolyKinds
, TypeFamilies
, TypeOperators
, FlexibleContexts
, MultiParamTypeClasses
, UndecidableSuperClasses
#-}
@sjoerdvisscher
sjoerdvisscher / equipment.hs
Last active May 23, 2020
Proarrow equipment in Hask
View equipment.hs
{-# LANGUAGE
GADTs
, DataKinds
, PolyKinds
, RankNTypes
, TypeOperators
, KindSignatures
, TypeApplications
, FlexibleContexts
, FlexibleInstances
@sjoerdvisscher
sjoerdvisscher / CatTagged.hs
Last active Jun 28, 2019
Kind-indexed categories with kind-tagging
View CatTagged.hs
{-# LANGUAGE
GADTs
, MultiParamTypeClasses
, RankNTypes
, TypeApplications
, TypeFamilies
, TypeOperators
, PolyKinds
, DataKinds
, InstanceSigs
@sjoerdvisscher
sjoerdvisscher / SuffixTree.hs
Created Dec 15, 2018
Suffix trees are united monoids
View SuffixTree.hs
{-# LANGUAGE OverloadedStrings, FlexibleInstances #-}
import qualified Data.Map as M
import Data.List
import Data.String
import Data.Functor
newtype SuffixTree a = ST (M.Map a (SuffixTree a)) deriving (Eq, Ord)
instance Ord a => Semigroup (SuffixTree a) where
You can’t perform that action at this time.