Skip to content

Instantly share code, notes, and snippets.

Luke Palmer luqui

Block or report user

Report or block luqui

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
luqui / foldl.hs
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
luqui / higher_products.hs
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
View monadcomplex.hs
-- 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)
luqui / baseball.html
Last active Feb 27, 2017
HTML help for Luke J
View baseball.html
<!DOCTYPE html>
<style type="text/css">
h1 {
font-size: 48pt;
text-align: left;
text-indent: 48px;
color: #000;
luqui / dragon.hs
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

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

1 2
3 4
luqui / howtowrite.hs
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
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
luqui / intervals.txt
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
This is study for playing the Haken Continuum.
Root: 1 : 0
P2: 9/8 : 2 +3c
Fourth: 4/3 : 5 -2c
luqui / gist:7611127
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.