Skip to content

Instantly share code, notes, and snippets.

@LightAndLight
LightAndLight / lex-parse-megaparsec.lhs
Last active November 21, 2023 15:26
Lexing and parsing in Megaparsec
\begin{code}
{-# LANGUAGE TypeFamilies #-}
module Parser where
import Control.Applicative ((*>), (<|>))
import Control.Monad (void)
import Data.Functor (($>))
import Data.List.NonEmpty (NonEmpty(..))
import Data.Maybe (fromJust)
{-# 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 =
@LightAndLight
LightAndLight / wat.py
Last active September 19, 2021 23:01
Python `wat`s
#########
# What happens when you run this?
print(1 + 0001)
# Does this code run? If not- why? If so- what is the value of `result`?
class Foo:
foo = 0
@LightAndLight
LightAndLight / Todolist.md
Last active August 27, 2021 09:27
To-do list spec

Write a command line todo-list app.

Running the program should load you into a REPL (read-eval-print loop).

A user should be able to enter a command by typing: COMMAND:argument i.e. a single word command followed by a colon, with everything to the right of the colon being the argument, then hitting the enter key. If a command takes no argument then the user should be allowed to omit the colon.

Implement the following 5 commands:

  1. "quit" (takes no arguments) - exits the application
{-# 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