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
gelisam / LocalInstance.hs
Created Jun 8, 2019
providing a local instance
View LocalInstance.hs
-- in response to https://twitter.com/mstk/status/1137162185266696192
{-# 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
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
gelisam / SpeedyTraverse.hs
Last active Apr 15, 2019
benchmarking various implementations of parallel traverse
View SpeedyTraverse.hs
-- in response to https://twitter.com/snoyberg/status/1116710317554315265
--
-- 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
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
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
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 https://www.reddit.com/r/haskell/comments/a50xpr/datahaskell_solve_this_small_problem_to_fill_some/
{-# 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)
@gelisam
gelisam / MkHList.hs
Last active Dec 7, 2018
a polyvariadic function returning a GADT
View MkHList.hs
-- in response to https://twitter.com/Iceland_jack/status/1070073876829429760
{-# LANGUAGE AllowAmbiguousTypes, DataKinds, FlexibleInstances, GADTs, InstanceSigs, ScopedTypeVariables, TypeApplications, TypeFamilies, TypeOperators #-}
module Main where
import Test.DocTest
-- The challenge is to define a polymorphic 'mkHList' which can be specialized
-- to all of those types:
--
-- mkList :: HList '[]
-- mkList :: d -> HList (d ': '[])
@gelisam
gelisam / FreeArrow.hs
Created Nov 24, 2018
An explanation of free Arrows
View FreeArrow.hs
{-# LANGUAGE Arrows, GADTs, LambdaCase, RankNTypes, ScopedTypeVariables #-}
module FreeArrow where
import Test.DocTest
import Prelude hiding (id, (.))
import Control.Arrow
import Control.Category
import Control.Monad.Trans.Class
import Control.Monad.Trans.Writer
import System.IO
@gelisam
gelisam / WordCount.hs
Created Nov 15, 2018
an exploration of monoidal word-counting
View WordCount.hs
-- an exploration of monoidal word-counting
{-# LANGUAGE BangPatterns #-}
module Main where
import Data.Char
import Data.List
import Data.Semigroup
-- I will implement wordcount several times. One of the goal
@gelisam
gelisam / EIO.hs
Last active Feb 8, 2019
Keeping track of which exceptions have and haven't been handled
View EIO.hs
-- a continuation of https://gist.github.com/gelisam/137effb33d2777328d366dcb563d8d13
{-# LANGUAGE FlexibleContexts, FlexibleInstances, GeneralizedNewtypeDeriving, LambdaCase, MultiParamTypeClasses #-}
module EIO where
import Control.Monad
import Data.Void
import Test.DocTest
import qualified Control.Exception as E
You can’t perform that action at this time.