Skip to content

Instantly share code, notes, and snippets.

View edsko's full-sized avatar

Edsko de Vries edsko

View GitHub Profile
-- | Pattern match on 'HasField'
--
-- This is intended to be used together with 'matchHasField'. Example usage:
--
-- > data Foo a
-- >
-- > instance HasField "fooX" (Foo a) Int where ..
-- > instance HasField "fooY" (Foo a) [a] where ..
-- >
-- > _example :: Foo Char -> (Int, [Char])
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wall #-}
module TypeLevelComposition where
@edsko
edsko / NatExample.hs
Last active September 13, 2021 06:54
newtype Nat (n :: N) = UnsafeInt Int
deriving Show via Int
data IsNat (n :: N) where
IsZero :: IsNat Z
IsSucc :: Nat n -> IsNat (S n)
toIsNat :: Nat n -> IsNat n
toIsNat (UnsafeInt 0) = unsafeCoerce IsZero
toIsNat (UnsafeInt n) = unsafeCoerce (IsSucc (UnsafeInt (pred n)))
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
#!/bin/bash
if [ ! -n "$1" ]; then
export ACTIVATED=""
if [ -n "$PRE_ACTIVATED_PATH" ]; then
export PATH="$PRE_ACTIVATED_PATH"
unset PRE_ACTIVATED_PATH
fi
{-# LANGUAGE ConstraintKinds #-}
{-# OPTIONS_GHC -Wno-redundant-constraints #-}
module edundantConstraints (
keepRedundantConstraint
) where
-- | Can be used to silence individual "redundant constraint" warnings
--
-- > foo :: ConstraintUsefulForDebugging => ...
{-# LANGUAGE RecordWildCards #-}
module SoundSeries.Util.SoupParser (
SoupParser
, parseSoup
-- * Combinators
, satisfy
, anyToken
, skipUntil
, lookupAttr
-- | Recover tree structure from linearized form
--
-- Suppose we have a list of strings
--
-- > A
-- > B
-- > C
-- > D
-- > E
-- > F
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
{-# OPTIONS_GHC -Wall #-}
import Control.Monad.Reader
import Data.Coerce
import Test.QuickCheck.Gen
import Test.QuickCheck.Monadic
@edsko
edsko / Sketch_QSM_LTL.hs
Created February 15, 2019 14:58
Using LTL formulae to check system states in quickcheck-state-machine
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StandaloneDeriving #-}
module Main where
import Data.IORef
import Data.TreeDiff