This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type LoadedData<A> = | |
<B>(f: (a: A) => B, g: (e: Error) => B, b: B) => B; | |
function loaded<A>(a: A): LoadedData<A> { | |
return <B>(f: (a: A) => B, error: (e: Error) => B, empty: B) => f(a); | |
} | |
function error<A>(e: Error): LoadedData<A> { | |
return <B>(success: (a: A) => B, f: (e: Error) => B, empty: B) => f(e); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Payments where | |
data Customer = Customer { name :: String, age :: Int } deriving (Eq, Ord, Show) | |
-- I know partial record fields is an anti-pattern, but who's counting? | |
data Payment | |
= Cash { customer :: Customer, amount :: Double } | |
| Credit { customer :: Customer, amount :: Double, cardNumber :: Int } | |
| Check { customer :: Customer, amount :: Double, routingNumber :: Int, accountNumber :: Int } | |
deriving (Eq, Ord, Show) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env nix-shell | |
#! nix-shell -i "emacs --batch -l $HOME/.emacs.d/core/core-load-paths.el -l" -p emacs26-nox | |
(require 'core-configuration-layer) | |
(configuration-layer/discover-layers) | |
(configuration-layer/make-all-packages nil) | |
(princ "p:\n") | |
(princ "let checked = n:\n") | |
(princ " let p' = p.${n} or null;\n") | |
(princ " in if p'.meta.broken or false then null else p';\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE ScopedTypeVariables, Rank2Types #-} | |
module ScottEncoding where | |
import Prelude hiding (null, length, map, foldl, foldr, take, fst, snd, curry, uncurry, concat, zip, (++)) | |
newtype SMaybe a | |
= SMaybe { runMaybe :: forall b. b -> (a -> b) -> b } | |
newtype SList a | |
= SList { runList :: forall b. b -> (a -> SList a -> b) -> b } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Prelude Language.Haskell.TH.Cleanup Generics.Deriving.TH | |
λ data X = A | B | |
Prelude Language.Haskell.TH.Cleanup Generics.Deriving.TH | |
λ putStrLn $(simplifiedTH =<< deriveAll0 ''X) | |
instance Generic (X :: *) | |
where type Rep (X :: *) = D1 ('MetaData "X" "Ghci3" "interactive" 'False) (:+: (C1 ('MetaCons "A" 'PrefixI 'False) U1) (C1 ('MetaCons "B" 'PrefixI 'False) U1)) | |
from val_0 = case val_0 of | |
y_1 -> M1 (case y_1 of | |
A -> L1 (M1 U1) | |
B -> R1 (M1 U1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open import Data.List | |
open import Data.List.Properties | |
open import Relation.Binary.PropositionalEquality | |
record ReverseFunction : Set₁ where | |
field | |
f : ∀ {A} → List A → List A | |
rev : ∀ {A} (xs ys : List A) → f (xs ++ ys) ≡ f ys ++ f xs | |
sing : ∀ {A} (x : A) → f (x ∷ []) ≡ x ∷ [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Example (Example, example) where | |
import Data.Functor (($>)) | |
import Control.Lens (Prism', prism') | |
import Control.Monad (guard) | |
data Example | |
= Example String | |
deriving (Eq, Ord, Show) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE ExistentialQuantification #-} | |
{-# LANGUAGE PolyKinds #-} | |
{-# LANGUAGE RankNTypes #-} | |
import Control.Applicative | |
import Control.Comonad | |
import Control.Monad | |
import Data.Functor.Compose | |
import Data.Functor.Contravariant | |
import qualified Data.Functor.Contravariant.Day as Contravariant |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Functor.Invariant | |
class Invariant f => ApplyDivide f where | |
apdivide :: (a -> b -> c) -> (c -> (a, b)) -> f a -> f b -> f c | |
-- Example | |
data Semigroup' a | |
= Semigroup' { append :: a -> a -> a } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
removeModName :: Name -> Name | |
removeModName = | |
filterModName (const False) | |
removeAllModNames :: Dec -> Dec | |
removeAllModNames = | |
transformOnOf (_SigD . _2) typeChildren (typeName %~ removeModName) . | |
transformOnOf (_ValD . _2 . bodyExp) expChildren (expName %~ removeModName) | |
simplify :: Dec -> Dec |