Skip to content

Instantly share code, notes, and snippets.

{-# language DataKinds, GADTs, DuplicateRecordFields, StandaloneDeriving #-}
module Questions where
import Data.Kind (Type)
data Nat = Z | S Nat
deriving Show
data Vec :: Nat -> Type -> Type where
Nil :: Vec 'Z a
{-# options_ghc -Wall -Werror #-}
module Env where
import Data.Maybe (fromMaybe)
import qualified System.Environment
data LogLevel = DEBUG | INFO | WARN | ERROR
deriving (Show, Read)
newtype Parser a = Parser { parse :: String -> IO a }
import Data.Semigroup (stimes)
import qualified Data.List as List
import Prelude hiding (words)
data Layout a = Space | Content a
deriving (Eq, Show)
layout :: b -> (a -> b) -> Layout a -> b
layout space f c =
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ConstraintKinds #-}
@LightAndLight
LightAndLight / neuron.md
Created June 30, 2021 11:50
neuron questions

Suppose I have two zettels, A and B:

A.md        B.md

Then I link from B to A with something like, "[[A]] provides a good summary of topic blah".

I now have a graph like this:

--- a/cryptohash-sha1.cabal
+++ b/cryptohash-sha1.cabal
@@ -66,7 +66,7 @@
library
default-language: Haskell2010
- build-depends: base >= 4.5 && < 4.15
+ build-depends: base >= 4.5 && < 5
, bytestring >= 0.9.2 && < 0.11
@LightAndLight
LightAndLight / Json.hs
Created August 19, 2020 05:15
typed json access with paths
{-# language GADTs, KindSignatures, StandaloneDeriving #-}
module Json
( JsonType(..), SomeJsonType(..)
, Segment(..)
, prettySegment
, Path(..)
, append
, prettyPath
, JsonError(..)
, typeOf
command {
name = "ls",
options = [
Flag{ name = "long", short = 'l' },
Flag{ name = "recursive", short = 'R', long = "recursive" },
Option{ name = "block-size", long = "block-size", type = Int, default = None },
Option{
name = "color",
long = "color",
@LightAndLight
LightAndLight / Rename.hs
Last active June 28, 2020 04:14
Injective renamings and well-typed, staged metaprogramming
{- | Calculating injective renamings
Say you have typing environment like [x : Int, y : Bool]. In your AST,
variables are represented by natural numbers that index into the environment.
So under this environment, `x` is represented by `0` and `y` is represented
by `1`. During type checking, information about a variable can be found by
indexing into that environment. Similarly, the environment of a
closure can be compiled to array, with the variable lookup being compiled to
array indexing. This approach is known as 'de bruijn indices'.
@LightAndLight
LightAndLight / RPC.hs
Created March 11, 2020 06:43
Sketch of well-typed RPC
{-# language DataKinds, GADTs, ScopedTypeVariables #-}
{-# language RankNTypes, TypeApplications #-}
{-# language LambdaCase #-}
{-# language ImplicitParams #-}
module Server where
import Data.Bifunctor (first)
import Data.ByteString (ByteString)
import Data.Proxy
import Data.Serialize