Skip to content

Instantly share code, notes, and snippets.

View tomjaguarpaw's full-sized avatar

Tom Ellis tomjaguarpaw

View GitHub Profile
{-# LANGUAGE RecordWildCards, PatternGuards, ViewPatterns #-}
module Cabal(run, readCabal, extractCabal) where
import Control.Monad.Extra
import Control.Exception.Extra
import Data.Char
import Data.List.Extra
import Data.Maybe
import Data.Functor
@tomjaguarpaw
tomjaguarpaw / traverseNubOf.hs
Last active November 2, 2016 17:39
traverseNubOf
-- | Traverse the structure using the traversal but memoize the
-- results of the transforming function; this means that the function
-- is called once for every unique element.
--
-- NB: I can't work out how to do this with only one optic argument,
-- but it should be possible.
--
-- prop> traverseNubOf (traverse._1) (traverse._1) (\x -> do print x; return (-x)) [(2,10),(2,20),(1,30),(1,40),(3,50),(3,60)]
-- 1
-- 2
@tomjaguarpaw
tomjaguarpaw / lensesForArrows.lhs
Last active June 19, 2018 21:14
Lenses for Arrows describes how the Lens datatype from Control.Lens can be generalise to support arrows.
> {-# LANGUAGE Rank2Types #-}
>
> import Prelude hiding (id)
> import Data.Functor.Constant (Constant(Constant), getConstant)
> import Control.Arrow (Arrow, arr, first, Kleisli(Kleisli), runKleisli, (&&&))
> import Control.Category ((<<<))
> import Control.Lens (sequenceAOf)
> import qualified Control.Lens as L
> import qualified Control.Lens.Internal.Setter as LS
> import Data.Profunctor (Profunctor, rmap)