Instantly share code, notes, and snippets.

# Luke Palmerluqui

• Sort options
Last active Dec 27, 2019
Example of how to get intermediate results from a Fold
View foldl.hs
 import qualified Control.Foldl as Foldl average :: Foldl.Fold Double Double average = (/) <\$> Foldl.sum <*> Foldl.genericLength -- This could have been done more easily with the Foldl.scan function, but -- I wanted to demonstrate how to access the intermediate states manually. averages :: [Double] -> [Double] averages xs | Foldl.Fold step s0 obs <- average
Last active Sep 11, 2018
Higher-kinded products using "axiomatic types"
View higher_products.hs
 {-# OPTIONS -fdefer-type-errors #-} {-# LANGUAGE DataKinds, PolyKinds, TypeFamilies, TypeOperators, RankNTypes, GADTs, TypeApplications, ScopedTypeVariables, UndecidableInstances, MultiParamTypeClasses, TypeInType, TypeSynonymInstances, FlexibleInstances, InstanceSigs, FlexibleContexts #-} import Prelude hiding (id, (.)) import Control.Category import Data.Kind (Type) import Unsafe.Coerce import Data.Type.Equality type family (~>) :: k -> k -> Type
Last active Apr 15, 2017
 -- In an alternate universe of Haskell where this worked... data (Num a) => Complex a = a :+ a instance Functor Complex where fmap f (x :+ y) = f x :+ f y instance Monad Complex where return x = x :+ 0 join ((a :+ b) :+ (c :+ d)) = (a - d) :+ (b + c)
Last active Feb 27, 2017
HTML help for Luke J
View baseball.html

Created Dec 16, 2016
dragon curve experiments
View dragon.hs
 {-# LANGUAGE RankNTypes, GADTs, ConstraintKinds, ScopedTypeVariables, DeriveFunctor #-} import Data.Monoid import Data.Foldable (toList) import Data.Constraint (Dict(..)) import qualified Data.DList as DList import qualified Data.Sequence as Seq class (Functor f) => DragonList f where singleton :: a -> f a
Last active Aug 29, 2015
View table.md

Really? `<table>` isn't available in markdown?

 1 2 3 4
Last active Aug 29, 2015
How to write this book
View howtowrite.hs
 import Data.List (intercalate) write :: String -> String write = intercalate ". " . map (\word -> "Write " ++ show word) . words howToWrite :: String howToWrite = "How to write this book: " ++ write howToWrite {- >>> putStrLn \$ take 1000 howToWrite
Created Feb 7, 2014
View russell.idris
 data Set : Type where Comp : (Set -> Type) -> Set elt : Set -> Set -> Type elt (Comp f) = f W : Set W = Comp (\A => Not (A `elt` A)) Russell : Type
Created Nov 28, 2013
An exploration of "small-ratio" musical intervals, compared to equal temperament.
View intervals.txt
 An exploration of "small-ratio" musical intervals, compared to equal temperament. Each interval has a perfect ratio before the colon, and a number of semitones with a cents (100th of a semitone) correction approximation. This is study for playing the Haken Continuum. Root: 1 : 0 P2: 9/8 : 2 +3c Fourth: 4/3 : 5 -2c
Created Nov 23, 2013
A neat list-like monoid that supports extracting information from both ends, even with undefined values in the middle.
View gist:7611127
 {-# LANGUAGE RankNTypes #-} import Data.Foldable import Data.Monoid newtype M a = M { getM :: forall m. Monoid m => (a -> m) -> m } instance Monoid (M a) where mempty = M \$ const mempty x `mappend` y = M \$ \f -> getM x f `mappend` getM y f
You can’t perform that action at this time.