Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View edsko's full-sized avatar

Edsko de Vries edsko

View GitHub Profile
@edsko
edsko / metadata.json
Last active August 3, 2022 11:04
Simple token transfer
{"valueParameterInfo":[],"timeParameterDescriptions":[],"roleDescriptions":[],"contractType":"Other","contractShortDescription":"Unknown","contractName":"Unknown","contractLongDescription":"We couldn't find information about this contract","choiceInfo":[]}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
module Data.Record.Anonymous.Internal.StrictVector (
Vector -- opaque
, MVector -- opaque
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Data.Record.Internal.GHC.Fresh (
MonadFresh(..)
, runFreshHsc
) where
import Data.IORef
import Control.Monad.Reader
-- | Alternate between @a@s and @b@s, starting and ending on a @a@
data Alternate a b =
AltDone a
| AltCons a b (Alternate a b)
instance Bifunctor Alternate where
bimap :: forall a a' b b'. (a -> a') -> (b -> b') -> Alternate a b -> Alternate a' b'
bimap f g = go
where
go :: Alternate a b -> Alternate a' b'
@edsko
edsko / CorrectedMeanStdDev.hs
Last active August 5, 2021 17:17
Mean and standard deviation corrected for a baseline
{-------------------------------------------------------------------------------
Mean and standard deviation, corrected for the baseline
By a slight abuse of notation we'll let X and Y range over two random
variables, as well as over two samples /drawn/ from those random variables.
We'll assume the sample size (for both variables) is N.
* Basic definitions:
> mean X = sum X_i / N (mean aka average)
@edsko
edsko / PHOAS.hs
Last active June 10, 2021 11:05
STLC in PHOAS to de Bruijn and back
module PHOAS where
import Data.Bifunctor
import Data.Functor.Const
import Data.Kind
import Data.SOP.NP
import GHC.Show
import Unsafe.Coerce (unsafeCoerce)
{-------------------------------------------------------------------------------
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
module NicerData where
import Data.Functor.Const
import Data.Functor.Identity
import Data.Typeable
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE UndecidableInstances #-}
module Main where
import Data.Char
import Data.Generics
import Data.Reflection
@edsko
edsko / RoleTest.hs
Last active April 13, 2021 12:07
Roles and higher-kinded types
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE RoleAnnotations #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -Wall #-}
module RoleTest where
import GHC.Exts
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds #-}