Skip to content

Instantly share code, notes, and snippets.

@Icelandjack
Icelandjack / Functor.hs
Last active October 10, 2020 16:06
Functor
{-
Every functor is a function mapping categories.
I want to specify them all in one place,
instance Functor (->) where
type Arr (->) = (<–) :- (->) :- End (->)
without having to specified partial applications of it
@Icelandjack
Icelandjack / circ.hs
Created October 3, 2020 11:40
Tree instance for Ap and Biap
instance (Applicative f, Treey tree) => Treey (Ap f tree) where
leaf :: Int -> Ap f tree
leaf = pure . leaf
(¦) :: Ap f tree -> Ap f tree -> Ap f tree
(¦) = liftA2 (¦)
instance (Biapplicative bi, Treey tree1, Treey tree2) => Treey (Biap bi tree1 tree2) where
leaf :: Int -> Biap bi tree1 tree2
leaf = liftA2 bipure leaf leaf
@Icelandjack
Icelandjack / showelem.hs
Last active September 17, 2020 22:31
instance pi n. Show (Fin n)
data SVec :: forall n a. Vec n a -> Type where
SVecO :: SVec VecO
SVecS :: Sing a -> SVec as -> SVec (a :> as)
type instance Sing @(Vec n a) = SVec @n @a
instance SingI VecO where
sing :: Sing VecO
sing = SVecO
@Icelandjack
Icelandjack / On.hs
Created January 13, 2020 12:13
singletons + On + via
{-# Language DataKinds #-}
{-# Language DerivingVia #-}
{-# Language FlexibleInstances #-}
{-# Language GADTs #-}
{-# Language InstanceSigs #-}
{-# Language PolyKinds #-}
{-# Language RankNTypes #-}
{-# Language ScopedTypeVariables #-}
{-# Language StandaloneKindSignatures #-}
{-# Language TypeApplications #-}
@Icelandjack
Icelandjack / state.hs
Last active November 5, 2019 11:46
Deriving via StateT s IO, (IO `Compose` State s) and (State s `Compose` IO)
-- https://stackoverflow.com/questions/49587122/type-variable-location-in-transformers
{-# Language DerivingVia #-}
import Control.Applicative
import Control.Monad.State
import Data.Functor.Compose
import Data.Functor.Identity
-- >> :instances StateT _ IO
@Icelandjack
Icelandjack / GhostsViaDepartedProofs.md
Last active November 10, 2019 15:46
Ghosts Via Departed Proofs

Ghosts of Departed Proofs introduces sortBy. It sorts using a comparison function a -> a -> Ordering named "comp". The name is then recorded in the return type: "this list is sorted by comp"!

type Cmp :: Type -> Type
type Cmp a = (a -> a -> Ordering)

sortBy :: Cmp a~~comp -&gt; [a] -&gt; SortedBy comp [a]
@Icelandjack
Icelandjack / Text.Read.Lex.isSymbolChar
Created October 13, 2019 13:57
filter Text.Read.Lex.isSymbolChar [minBound..]
!#$%&*+-./:<=>?@\^|~¡¢£¤¥¦§¨©¬®¯°±´¶·¸¿×÷˂˃˄˅˒˓˔˕˖˗˘˙˚˛˜˝˞˟˥˦˧˨˩˪˫˭˯˰˱˲˳˴˵˶˷˸˹˺˻˼˽˾˿͵;΄΅·϶҂՚՛՜՝՞՟։֊֍֎֏־׀׃׆׳״؆؇؈؉؊؋،؍؎؏؛؞؟٪٫٬٭۔۞۩۽۾܀܁܂܃܄܅܆܇܈܉܊܋܌܍߶߷߸߹࠰࠱࠲࠳࠴࠵࠶࠷࠸࠹࠺࠻࠼࠽࠾࡞।॥॰৲৳৺৻૰૱୰௳௴௵௶௷௸௹௺౿൹෴฿๏๚๛༁༂༃༄༅༆༇༈༉༊་༌།༎༏༐༑༒༓༔༕༖༗༚༛༜༝༞༟༴༶༸྅྾྿࿀࿁࿂࿃࿄࿅࿇࿈࿉࿊࿋࿌࿎࿏࿐࿑࿒࿓࿔࿕࿖࿗࿘࿙࿚၊။၌၍၎၏႞႟჻፠፡።፣፤፥፦፧፨᎐᎑᎒᎓᎔᎕᎖᎗᎘᎙᐀᙭᙮᛫᛬᛭᜵᜶។៕៖៘៙៚៛᠀᠁᠂᠃᠄᠅᠆᠇᠈᠉᠊᥀᥄᥅᧞᧟᧠᧡᧢᧣᧤᧥᧦᧧᧨᧩᧪᧫᧬᧭᧮᧯᧰᧱᧲᧳᧴᧵᧶᧷᧸᧹᧺᧻᧼᧽᧾᧿᨞᨟᪠᪡᪢᪣᪤᪥᪦᪨᪩᪪᪫᪬᪭᭚᭛᭜᭝᭞᭟᭠᭡᭢᭣᭤᭥᭦᭧᭨᭩᭪᭴᭵᭶᭷᭸᭹᭺᭻᭼᯼᯽᯾᯿᰻᰼᰽᰾᰿᱾᱿᳀᳁᳂᳃᳄᳅᳆᳇᳓᾽᾿῀῁῍῎῏῝῞῟῭΅`´῾‐‑‒–—―‖‗†‡•‣․‥…‧‰‱′″‴‵‶‷‸※‼‽‾‿⁀⁁⁂⁃⁄⁇⁈⁉⁊⁋⁌⁍⁎⁏⁐⁑⁒⁓⁔⁕⁖⁗⁘⁙⁚⁛⁜⁝⁞⁺⁻⁼₊₋₌₠₡₢₣₤₥₦₧₨₩₪₫€₭₮₯₰₱₲₳₴₵₶₷₸₹₺₻₼₽℀℁℃℄℅℆℈℉℔№℗℘℞℟℠℡™℣℥℧℩℮℺℻⅀⅁⅂⅃⅄⅊⅋⅌⅍⅏←↑→↓↔↕↖↗↘↙↚↛↜↝↞↟↠↡↢↣↤↥↦↧↨↩↪↫↬↭↮↯↰↱↲↳↴↵↶↷↸↹↺↻↼↽↾↿⇀⇁⇂⇃⇄⇅⇆⇇⇈⇉⇊⇋⇌⇍⇎⇏⇐⇑⇒⇓⇔⇕⇖⇗⇘⇙⇚⇛⇜⇝⇞⇟⇠⇡⇢⇣⇤⇥⇦⇧⇨⇩⇪⇫⇬⇭⇮⇯⇰⇱⇲⇳⇴⇵⇶⇷⇸⇹⇺⇻⇼⇽⇾⇿∀∁∂∃∄∅∆∇∈∉∊∋∌∍∎∏∐∑−∓∔∕∖∗∘∙√∛∜∝∞∟∠∡∢∣∤∥∦∧∨∩∪∫∬∭∮∯∰∱∲∳∴∵∶∷∸∹∺∻∼∽∾∿≀≁≂≃≄≅≆≇≈≉≊≋≌≍≎≏≐≑≒≓≔≕≖≗≘≙≚≛≜≝≞≟≠≡≢≣≤≥≦≧≨≩≪≫≬≭≮≯≰≱≲≳≴≵≶≷≸≹≺≻≼≽≾≿⊀⊁⊂⊃⊄⊅⊆⊇⊈⊉⊊⊋⊌⊍⊎⊏⊐⊑⊒⊓⊔⊕⊖⊗⊘⊙⊚⊛⊜⊝⊞⊟⊠⊡⊢⊣⊤⊥⊦⊧⊨⊩⊪⊫⊬⊭⊮⊯⊰⊱⊲⊳⊴⊵⊶⊷⊸⊹⊺⊻⊼⊽⊾⊿⋀⋁⋂⋃⋄⋅⋆⋇⋈⋉⋊⋋⋌⋍⋎⋏⋐⋑⋒⋓⋔⋕⋖⋗⋘⋙⋚⋛⋜⋝⋞⋟⋠⋡⋢⋣⋤⋥⋦⋧⋨⋩⋪⋫⋬⋭⋮⋯⋰⋱⋲⋳⋴⋵⋶⋷⋸⋹⋺⋻⋼⋽⋾⋿⌀⌁⌂⌃⌄⌅⌆⌇⌌⌍⌎⌏⌐⌑⌒⌓⌔⌕⌖⌗⌘⌙⌚⌛⌜⌝⌞⌟⌠⌡⌢⌣⌤⌥⌦⌧⌨⌫⌬⌭⌮⌯⌰⌱⌲⌳⌴⌵⌶⌷⌸⌹⌺⌻⌼⌽⌾⌿⍀⍁⍂⍃⍄⍅⍆⍇⍈⍉⍊⍋⍌⍍⍎⍏⍐⍑⍒⍓⍔⍕⍖⍗⍘⍙⍚⍛⍜⍝⍞⍟⍠⍡⍢⍣⍤⍥⍦⍧⍨⍩⍪⍫⍬⍭⍮⍯⍰⍱⍲⍳⍴
@Icelandjack
Icelandjack / repvia.hs
Created September 26, 2019 19:18
Deriving Comonad through many different ways
newtype (f `RepVia` via) a = RepVia (f a)
instance (Representable f, Coercible via (Rep f)) => Functor (f `RepVia` via) where
fmap :: forall a b. (a -> b) -> ((f `RepVia` via) a -> (f `RepVia` via) b)
fmap = coerce $ fmapRep @f @a @b
instance (Representable f, Coercible via (Rep f)) => Distributive (f `RepVia` via) where
collect :: forall g a b. Functor g => (a -> (f `RepVia` via) b) -> (g a -> (f `RepVia` via) (g b))
collect = coerce (collect @f @g @a @b)
@Icelandjack
Icelandjack / ComonadVia.hs
Created March 8, 2019 12:19
DerivingVia (Co Any Pair) and (Co All Pair)
{-# Language DeriveFunctor #-}
{-# Language DerivingVia #-}
{-# Language FlexibleContexts #-}
{-# Language FlexibleInstances #-}
{-# Language GADTs #-}
{-# Language GeneralizedNewtypeDeriving #-}
{-# Language InstanceSigs #-}
{-# Language ScopedTypeVariables #-}
{-# Language TypeApplications #-}
{-# Language TypeFamilies #-}
@Icelandjack
Icelandjack / Kleisli_Category.hs
Last active January 6, 2019 11:20
Kind-indexed Category instance for Kleisli
-- https://www.reddit.com/r/haskell/comments/abxem5/experimenting_with_kleisli_instance_of/
{-# Language TypeApplications #-}
{-# Language RankNTypes #-}
{-# Language DataKinds #-}
{-# Language KindSignatures #-}
{-# Language PolyKinds #-}
{-# Language TypeOperators #-}
{-# Language GADTs #-}
{-# Language TypeFamilies #-}