Skip to content

Instantly share code, notes, and snippets.

Samuel Gélineau gelisam

Block or report user

Report or block gelisam

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
gelisam / TestingCFromHaskell.hs
Last active Nov 11, 2019
using Haskell's QuickCheck to property-test C's qsort
View TestingCFromHaskell.hs
-- in response to
-- TLDR: yes, you can test C functions from Haskell; it's a bit painful to
-- call C from Haskell, but once you do, testing is the easy part!
{-# LANGUAGE QuasiQuotes, ScopedTypeVariables, TemplateHaskell #-}
module Main where
import Data.Foldable (for_)
import Data.Traversable (for)
import Foreign.C.Types (CInt, CSize)
gelisam / Handler.hs
Created Sep 29, 2019
A variant of my FunDay-based composable handlers which is compatible with ExcepT and friends.
View Handler.hs
-- A variant of
-- which suports ExceptT. Kind of.
{-# LANGUAGE FlexibleContexts, FlexibleInstances, MultiParamTypeClasses, PolyKinds, RankNTypes, TupleSections, TypeOperators, UndecidableInstances #-}
module Main where
import Test.DocTest
import Control.Monad.Except
import Control.Monad.Reader
import Control.Monad.State
import Control.Monad.Writer
gelisam / FunDay.hs
Last active Oct 2, 2019
a concrete use for FunDay, the right-adjoint of Day
View FunDay.hs
-- A concrete use case for the type which is to '(->)' as 'Day' is to '(,)'.
-- I call it "FunDay", but I don't know what its proper name is. I've been
-- trying to find a use for 'FunDay', and I think I've found a pretty neat one.
{-# LANGUAGE FlexibleContexts, FlexibleInstances, PolyKinds, RankNTypes, TypeSynonymInstances #-}
module Main where
import Test.DocTest
import Control.Monad.Except
import Control.Monad.Reader
gelisam / ShrinkingScopedPrograms.hs
Created Jul 1, 2019
writing Arbitrary instances for monadic DSLs which generate references
View ShrinkingScopedPrograms.hs
{-# LANGUAGE FlexibleInstances, GeneralizedNewtypeDeriving, LambdaCase #-}
module ShrinkingScopedPrograms where
import Test.DocTest
import Control.Monad.State
import Data.Map (Map)
import Test.QuickCheck
import qualified Data.Map as Map
-- $setup
gelisam / LocalInstance.hs
Created Jun 8, 2019
providing a local instance
View LocalInstance.hs
-- in response to
{-# LANGUAGE FlexibleContexts, FlexibleInstances, RankNTypes, ScopedTypeVariables #-}
module Main where
import Test.DocTest
import Data.Proxy
import Unsafe.Coerce
-- The goal is to implement a function
gelisam / EffectSystemsBenchmark.hs
Created Apr 25, 2019
effect-systems benchmark
View EffectSystemsBenchmark.hs
{-# LANGUAGE DataKinds, DeriveFunctor, FlexibleContexts, GADTs, LambdaCase, RankNTypes, ScopedTypeVariables, TypeApplications, TypeOperators #-}
module Main (main) where
import Criterion (bench, bgroup, nf)
import Criterion.Main (defaultMain)
import qualified Control.Monad.Trans.Class as Transformers
import qualified Control.Monad.Trans.Reader as Transformers
import qualified Control.Monad.Trans.State as Transformers
gelisam / SpeedyTraverse.hs
Last active Apr 15, 2019
benchmarking various implementations of parallel traverse
View SpeedyTraverse.hs
-- in response to
-- Green threads are very cheap, so I want to investigate under which
-- circumstances it is worth making the logic more complex in order to minimize
-- their number. So I wrote multiple implementations, ran them with a different
-- number of inputs, and with different task sizes.
-- On my four-capabilities machine, my observations are:
-- * With very small (10 μs) tasks, the single-threaded 'traverse' wins,
gelisam / Dag.hs
Created Mar 12, 2019
using indexed Monads to make illegal DAGs underrepresentable
View Dag.hs
{-# LANGUAGE FlexibleInstances, GADTs, MultiParamTypeClasses, RebindableSyntax #-}
import Data.Maybe
import Prelude (IO, putStrLn, ($), id, (.), fst, snd)
data Void
data Dag where
Dag :: Dag' a -> Dag
gelisam / Dyna.hs
Created Mar 10, 2019
dynamic programming using recursion schemes
View Dyna.hs
-- Solving a dynamic programming in many ways, including using existing
-- recursion schemes and by defining new ones. The problem of solving this
-- particular problem using recursion schemes was posed by Sandy Maguire.
{-# LANGUAGE FlexibleContexts, RankNTypes, TypeApplications, TypeFamilies, ScopedTypeVariables #-}
{-# OPTIONS -Wno-orphans #-}
module Dyna where
import Test.DocTest
import Data.Functor.Foldable (Base, Fix, Recursive(project), Corecursive(embed, ana), hylo, cataA)
gelisam / Main.hs
Created Dec 12, 2018
Averaged across persons, excluding legal fees, how much money had each person spent by time 6?
View Main.hs
-- in response to
{-# LANGUAGE BangPatterns, OverloadedStrings, RecordWildCards, ScopedTypeVariables #-}
module Main where
import Control.Category ((>>>))
import Data.Function ((&))
import Data.Map.Strict (Map, (!))
import Data.Set (Set)
import Test.DocTest (doctest)
You can’t perform that action at this time.