Skip to content

Instantly share code, notes, and snippets.

View tomjaguarpaw's full-sized avatar

tomjaguarpaw

View GitHub Profile
@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)
@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
{-# 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

stargazer

Structurally typed arguments and zero extra rubbish

-- Stargazer's, very small, API

-- An option can take a single string argument or nothing at all.
string  :: Schema String
nothing :: Schema ()
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
module Test2 where
data Proxy a = Proxy
@tomjaguarpaw
tomjaguarpaw / systems-theory-books.md
Last active August 19, 2019 15:10
Systems theory books
@tomjaguarpaw
tomjaguarpaw / dynamic-fields.hs
Last active September 21, 2019 17:11
Opaleye dynamic fields
-- Requires branch https://github.com/tomjaguarpaw/haskell-opaleye/tree/dynamic-fields
--
-- If you use this please contact me http://web.jaguarpaw.co.uk/~tom/contact/ and let me
-- know what you think.
import Data.String
import Opaleye
import Opaleye.Internal.Dynamic (SqlDynamic, Dynamic,
stringFromFields, stringUnpackspec)
@tomjaguarpaw
tomjaguarpaw / StrangeHashable.hs
Last active May 28, 2020 17:13
Strange hashable
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE DeriveGeneric #-}
{-# OPTIONS_GHC -Wall #-}
module StrangeHashable where
import Data.Hashable
import GHC.Generics (Generic)
data ListF a r = ConsF a r | NilF deriving Generic
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -Wall #-}
module Main where
import Control.Lens (makeLenses, use, (%=), (.=))
import Control.Monad (when)
import Control.Monad.Trans.State.Strict (evalState)
import Data.Traversable (for)
@tomjaguarpaw
tomjaguarpaw / addPoint.hs
Created January 5, 2024 09:32
addPoint product-profunctors
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
import Control.Applicative
import Data.Profunctor