Skip to content

Instantly share code, notes, and snippets.

-- | parseAlt "ok|
--
-- > parseAlt "one|two|three" `runParser` "four!"
-- Right ("","four!")
-- > parseAlt "one|two|three" `runParser` "one!"
-- Right ("one","!")
parseAlt :: forall (regexp :: Symbol) -> ParseAlt regexp => Parser String
parseAlt regexp = parseAlt' @(SplitPipe (ToList regexp))
-- | Implementation
@Icelandjack
Icelandjack / Phases.hs
Last active August 18, 2025 01:51
Phases, with Vault
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE GHC2021 #-}
import Control.Applicative
import Control.Monad.ST
import Data.Kind
import Data.Map (Map)
@Icelandjack
Icelandjack / Phases.hs
Last active July 21, 2025 12:46
Phases
{-# LANGUAGE PackageImports #-}
{-# options_ghc -Wno-partial-type-signatures #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE LambdaCase #-}
@Icelandjack
Icelandjack / Constraints.org
Last active May 28, 2025 21:28
Type Classes and Constraints

Reddit discussion.

Disclaimer 1: Type classes are great but they are not the right tool for every job. Enjoy some balance and balance to your balance.

Disclaimer 2: I should tidy this up but probably won’t.

Disclaimer 3: Yeah called it, better to be realistic.

Type classes are a language of their own, this is an attempt to document features and give a name to them.

@Icelandjack
Icelandjack / glossary.md
Last active March 31, 2025 00:09
_jack Glossary

A function mapped on each side.

Any function (profunctor/category) has "inputs" and "outputs". First argument: input (contravariant), second argument: output (covariant). covariant argument.

🟥🟦 :: 🟥 -> 🟦
🟦🟩 :: 🟦 -> 🟩

When composing, it works like domino pieces: 🀺 >>> 🁂 = 🀻 the connecting parts must be match but prefer using colours for it.

@Icelandjack
Icelandjack / diff.el
Created November 16, 2024 22:41
diff.el
;; Separate string with escaped '\\n' literals.
;; These '\\n' literals will be interpreted by `echo'.
;;
;; (broken "hello")
;; = "h\\ne\\nl\\nl\\no"
(defun broken (str)
(mapconcat
(lambda (x) (make-string 1 x))
str
"\\n"))
@Icelandjack
Icelandjack / Overriding.hs
Last active July 9, 2024 21:49
Zero-cost overriding
{-# Language DerivingVia #-}
{-# Language StandaloneKindSignatures #-}
-- Some imports and pragmas missing.
import GHC.Generics
import Control.Applicative
import GHC.TypeLits
import Data.Kind
import Data.Coerce
import Data.Monoid
@Icelandjack
Icelandjack / Overriding.hs
Created July 9, 2024 13:52
Changing Generic representation, using SOP style Code
-- this allows you to derive
--
-- data OneTwo = OneTwo { x :: Int, y :: Int }
-- deriving stock Generic
-- deriving (Semigroup, Monoid) via Overriding '[ '[Sum Int, Sum Int] ] Onetwo
-- | Override
newtype Override (code :: [[Type]]) a = Override { getOverride :: a }
type Overriding code a = Generically (Override code a)
@Icelandjack
Icelandjack / Yoneda_II.markdown
Last active April 8, 2024 11:08
Yoneda Intuition from Humble Beginnings

(previous Yoneda blog) (reddit) (twitter)

Yoneda Intuition from Humble Beginnings

Let's explore the Yoneda lemma. You don't need to be an advanced Haskeller to understand this. In fact I claim you will understand the first section fine if you're comfortable with map/fmap and id.

I am not out to motivate it, but we will explore Yoneda at the level of terms and at the level of types.

@Icelandjack
Icelandjack / NewtypeDeriving.markdown
Last active April 4, 2023 04:49
Newtype Deriving