Skip to content

Instantly share code, notes, and snippets.

title author
Indexed Profunctor optics
Oleg Grenrus

This post is a response to the Edward's tweet:

Now try to fit all of the indexed and index-preserving variants. ;) Edward Kmett
@Icelandjack
Icelandjack / RecordPatternDictionary.markdown
Last active August 7, 2017 09:09
Open Monad dictionary with record pattern synonym (and as patterns)
{-# Language PatternSynonyms #-}
{-# Language ViewPatterns    #-}

data DMonad m = DMonad
  (forall a.   a -> m a)
  (forall a b. m a -> (a -> m b) -> m b)
  (forall a.   String -> m a)

pattern Open :: (forall a. a -> [a]) -> (forall a a'. [a] -> (a -> [a']) -> [a']) -> (forall a. String -> [a]) -> xxx
@nurpax
nurpax / char-rnn.hs
Last active November 9, 2017 15:50
Some char-rnn generated Haskell based on training with the GHC HEAD source code
-- buildPatSynDetails, so this is a mempty, even the type
-- we generate the same location here.
hsConDeclDetails _ = pprPanic "tcLHsBindsCtOrigin" (ppr val_val_binds)
--------------------
zonkForeignCall :: FlexibleInfo -> CoreBind
-> Maybe FreeVars -- True <=> supplied EndBinds
-> RecFlag
-> Cts -> ForeignOpt Id
@dalaing
dalaing / Demo.hs
Created January 18, 2018 12:18
Bound Demo
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE StandaloneDeriving #-}
module Demo where
@imeckler
imeckler / gist:3885281
Created October 13, 2012 16:39
Pithy finite state machine in haskell
import Control.Monad
import Data.Maybe
import Prelude hiding (any, elem)
import Data.Foldable
type State = String
type Map a b = [(a, b)]
-- In Map State (Map Char (m State)), the monad m determines the kind of FSM that is being run.
-- If m = [] (or Set), these functions work as a NFA. If m = Maybe, we essentially have a DFA.
{-# LANGUAGE TemplateHaskell, TypeFamilies, DeriveFunctor, DeriveFoldable, DeriveTraversable, FlexibleInstances #-}
{-# LANGUAGE LambdaCase, FlexibleContexts, UndecidableInstances, TypeOperators, DataKinds, MultiParamTypeClasses #-}
module Sem where
import Data.Algebra
import Data.Constraint
import Data.Constraint.Class1
import Data.Functor.Free
class BaseSem a where
@Icelandjack
Icelandjack / gist:3a98d3979879fd9415bbde3761c51760
Created March 18, 2018 14:41
HFree + QuantifiedConstraints
-- Response to
-- https://gist.github.com/sjoerdvisscher/e8ed8ca8f3b6420b4aebe020b9e8e235
-- https://twitter.com/sjoerd_visscher/status/975375241932427265
{-# Language QuantifiedConstraints, TypeOperators, RankNTypes, GADTs, ConstraintKinds, MultiParamTypeClasses, FlexibleInstances, UndecidableInstances, PolyKinds, InstanceSigs #-}
import Data.Coerce
type f ~> g = forall x. f x -> g x
@jmitchell
jmitchell / Chess.dhall
Last active April 4, 2018 21:04
WIP: Chess in Dhall
let List/replicate = https://ipfs.io/ipfs/QmQ8w5PLcsNz56dMvRtq54vbuPe9cNnCCUXAQp6xLc6Ccx/Prelude/List/replicate in
let File = Natural in
let Rank = Natural in
let Square = { file : File, rank : Rank } in
let Move = { from : Square, to : Square } in
let Side = < white : {} | black : {} > in
let white = < white = {=} | black : {} > in
let black = < black = {=} | white : {} > in
@ekmett
ekmett / QC.hs
Created March 8, 2018 19:44
Using Quantified Constraints for Optics -- untypechecked (no compiler available)
{-# language TypeInType, QuantifiedConstraints, ConstraintKinds, RankNTypes, UndecidableInstances, MultiParamTypeClasses, TypeFamilies, KindSignatures #-}
module QC where
import Data.Constraint
import Data.Functor.Contravariant
import Data.Kind
import Data.Profunctor
type C = (Type -> Type) -> (Type -> Type -> Type) -> Constraint
@sjoerdvisscher
sjoerdvisscher / updatemonad.hs
Created May 8, 2013 09:21
The update monad which generalizes the reader, writer and state monad from http://homepages.inf.ed.ac.uk/s1225336/talks/types13.pdf
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances, MultiParamTypeClasses #-}
import Data.Monoid
import Data.Monoid.Action
import Data.Monoid.MList (SM(..))
import Control.Monad.Trans.Class
newtype UpdateT p s m a = UpdateT { runUpdateT :: s -> m (p, a) }