Skip to content

Instantly share code, notes, and snippets.

View edsko's full-sized avatar

Edsko de Vries edsko

View GitHub Profile
@edsko
edsko / cabal-run.c
Last active August 14, 2018 08:13
Utility to find and run an executable in the `dist-newstyle` directory
#include <dirent.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
int findUp(char* cwd, const char* needle, unsigned char typ);
void findDown(char* cwd, const char* needle, unsigned char typ, char* out);
@edsko
edsko / Collect.hs
Last active September 10, 2018 15:15
Applicative-only, spaceleak-free version of 'WriterT'
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE UndecidableInstances #-}
module Main where
import Data.Functor.Identity
import Data.Monoid
@edsko
edsko / DepFn.hs
Created October 23, 2018 14:06
Testing dependent functions with QuickCheck
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeFamilyDependencies #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
-- | Error handling
--
-- Intended for qualified import
--
-- > import Ouroboros.Storage.Util.ErrorHandling (ErrorHandling(..))
-- > import qualified Ouroboros.Storage.Util.ErrorHandling as EH
-- | Convert 'Double' to fixed precision
--
-- For precision 'E1', we have
--
-- > 1.000 1.010 1.040 1.049 1.050 1.051 1.090 1.100
-- > floor | 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.1
-- > round | 1.0 1.0 1.0 1.0 1.0(*) 1.1 1.1 1.1
-- > ceiling | 1.0 1.1 1.1 1.1 1.1 1.1 1.1 1.1
--
-- (*): See <https://en.wikipedia.org/wiki/IEEE_754#Rounding_rules>
@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
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
{-# OPTIONS_GHC -Wall #-}
import Control.Monad.Reader
import Data.Coerce
import Test.QuickCheck.Gen
import Test.QuickCheck.Monadic
-- | Recover tree structure from linearized form
--
-- Suppose we have a list of strings
--
-- > A
-- > B
-- > C
-- > D
-- > E
-- > F
{-# LANGUAGE RecordWildCards #-}
module SoundSeries.Util.SoupParser (
SoupParser
, parseSoup
-- * Combinators
, satisfy
, anyToken
, skipUntil
, lookupAttr
{-# LANGUAGE ConstraintKinds #-}
{-# OPTIONS_GHC -Wno-redundant-constraints #-}
module edundantConstraints (
keepRedundantConstraint
) where
-- | Can be used to silence individual "redundant constraint" warnings
--
-- > foo :: ConstraintUsefulForDebugging => ...