Skip to content

Instantly share code, notes, and snippets.

Edsko de Vries edsko

Block or report user

Report or block edsko

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View HoistPropertyM.hs
{-# 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 Feb 15, 2019
Using LTL formulae to check system states in quickcheck-state-machine
View Sketch_QSM_LTL.hs
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StandaloneDeriving #-}
module Main where
import Data.IORef
import Data.TreeDiff
View doubleToFixed.hs
-- | 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>
View ErrorHandling.hs
{-# 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
@edsko
edsko / DepFn.hs
Created Oct 23, 2018
Testing dependent functions with QuickCheck
View DepFn.hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeFamilyDependencies #-}
{-# LANGUAGE TypeInType #-}
@edsko
edsko / Collect.hs
Last active Sep 10, 2018
Applicative-only, spaceleak-free version of 'WriterT'
View Collect.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE UndecidableInstances #-}
module Main where
import Data.Functor.Identity
import Data.Monoid
@edsko
edsko / cabal-run.c
Last active Aug 14, 2018
Utility to find and run an executable in the `dist-newstyle` directory
View cabal-run.c
#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);
View HdWalletNotes.hs
{-# LANGUAGE GADTs #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# OPTIONS_GHC -Wall -fno-warn-incomplete-patterns #-}
module HdWalletNotes where
{-------------------------------------------------------------------------------
This module is a simple Haskell model of BIP-32, with a focus on why and
how hardening works. We start with some types for which we need no further
View OopInHaskell.hs
module Blog where
import Prelude hiding ((.), id)
import Control.Category
import Data.Bifunctor
{-------------------------------------------------------------------------------
Fixed points
-------------------------------------------------------------------------------}
View SOPExt.hs
type family Repeat (n :: Nat) (a :: *) :: [*] where
Repeat 'Zero a = '[]
Repeat ('Succ n) a = a ': Repeat n a
fromHomSum :: SNat n -> NS f (Repeat n a) -> f a
fromHomSum SZero ns = case ns of {}
fromHomSum (SSucc _) (Z a) = a
fromHomSum (SSucc n) (S as) = fromHomSum n as
toHomProd :: [f a] -> (forall n. SListI (Repeat n a) => SNat n -> NP f (Repeat n a) -> b) -> b
You can’t perform that action at this time.