Skip to content

Instantly share code, notes, and snippets.

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)
gelisam / MkHList.hs
Last active Dec 7, 2018
a polyvariadic function returning a GADT
View MkHList.hs
-- in response to
{-# 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 / 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 / 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 / EIO.hs
Last active Feb 8, 2019
Keeping track of which exceptions have and haven't been handled
View EIO.hs
-- a continuation of
{-# LANGUAGE FlexibleContexts, FlexibleInstances, GeneralizedNewtypeDeriving, LambdaCase, MultiParamTypeClasses #-}
module EIO where
import Control.Monad
import Data.Void
import Test.DocTest
import qualified Control.Exception as E
gelisam / CouldBe.hs
Last active Mar 7, 2019
Keeping track of which errors have and haven't been handled
View CouldBe.hs
-- in response to
{-# LANGUAGE FlexibleContexts, FlexibleInstances, MultiParamTypeClasses #-}
module CouldBe where
import Control.Monad
import Data.Void
-- Here is an alternate, much simpler solution to the problem of keeping track of which errors have
-- and haven't been handled. It doesn't use prisms nor generics, it simply uses the monad
gelisam / DashDashArguments.hs
Created Nov 6, 2018
Named arguments in Haskell
View DashDashArguments.hs
-- in response to
{-# LANGUAGE DataKinds, FlexibleContexts, FlexibleInstances, GADTs, MultiParamTypeClasses, TypeOperators #-}
module DashDashArguments where
import GHC.TypeLits
import Test.DocTest
-- The challenge is to implement named arguments in this style:
You can’t perform that action at this time.