Skip to content

Instantly share code, notes, and snippets.

View barrucadu's full-sized avatar

Michael Walker barrucadu

View GitHub Profile
@inproceedings{parmonad,
title={{A Monad for Deterministic Parallelism}},
author={Marlow, Simon and Newton, Ryan and Peyton Jones, Simon},
booktitle={ACM SIGPLAN Notices},
volume={46},
number={12},
pages={71--82},
year={2011},
organization={ACM}
}
@barrucadu
barrucadu / Find.hs
Created February 26, 2015 15:48
One-file search-party, specialised to IO.
{-# LANGUAGE RankNTypes, ImpredicativeTypes #-}
-- | Concurrent nondeterministic search.
module Find
( -- * @Find@ monad
Find
, runFind
, unsafeRunFind
, hasResult
-- * Basic Searches
@barrucadu
barrucadu / modular.hs
Last active August 29, 2015 14:17
Modular arithmetic, with the modulus encoded in the type to statically enforce consistency.
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE DataKinds #-}
module Modular (Modular, modulus) where
import GHC.TypeLits
-- | Integers, modulo some (type-specified) natural. This forms a
-- field if the modulus is a prime.
newtype Modular (n :: Nat) = Mod { unMod :: Integer } deriving (Eq, Ord)
@barrucadu
barrucadu / coapplicative.hs
Created March 24, 2015 23:38
Coapplicative functors in Haskell
-- Because of the type of 'from', 'Coaplicative' must correspond to "non-empty containers", for the usual hand-wavy definition of "container".
class Functor f => Coapplicative f where
from :: f a -> a
separate :: f (Either a b) -> Either (f a) (f b)
instance Coapplicative Identity where
from (Identity a) = a
separate (Identity (Left a)) = Left (Identity a)
separate (Identity (Right b)) = Right (Identity b)
@barrucadu
barrucadu / input.hs
Created April 3, 2015 16:53
NYHC demodularisation (Data/Maybe.hs not included, but all it does is define Maybe)
module Test where
import Data.Maybe
a = "hello world"
const a b = a
id a = a
@barrucadu
barrucadu / output.hs
Created April 5, 2015 13:39
More demodularisation
module Test where
class Data.Functor.Functor f where
fmap :: (a -> b) -> f a -> f b
class Data.Functor.Functor f => Control.Applicative.Applicative f
where
pure :: a -> f a
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCkI6P8XPkAQ/L7mmZY9EXQfHhmrd2ImYPEqExDUa+3xHJWw2Ha8gJ5EMk36QcTHFwok9dWuvjHk+ZCeodW99euuB6ZIuKjIb5Ru+3ZJvWisykTV32Tl+P1Pgi0BijKo9GFk2HJ3HemR2n0cZXvyEJuUvKwncdPWt6Fsr629gPcT7I6M/HwdXLHt9c7r64GhRCLcthKptUDGhVFls9v0w7ReNFjq81P9NO2SvPPJfGO7aAW96QyQdlF4OdtZyOTBy2Fr0FoHNrOZQ6XtwjnY5K8SZ68J05Fy/rHDt7bO3X2dcROnQTWHBMVSjLYnLlL5xlQBp0fj/VblRkiCuoVduT3 msw504@csteach0
-- |Default load file for the Mueval plugin. Imports and definitions
-- can be added to this file to make them available to evaluated
-- expressions.
module L where
-- Use more generic versions of things
import Prelude hiding ( (.), id -- Control.Category
, foldr, foldr', foldl, foldl', foldr1, foldl1
, and, or, any, all, sum, product
, maximum, maximumBy, minimum, minimumBy
{-# LANGUAGE GADTs #-}
module FizzBuzz where
import Data.Typeable
data Wrapper where
Wrap :: Typeable a => a -> Wrapper
instance Show Wrapper where
import Data.List
divisors :: Int -> [Int]
divisors n = (1:) $ concat [ nub [x, q] | x <- [2..lim], let (q,r) = quotRem n x, r == 0 ] where
lim = floor . sqrt $ fromIntegral n
triangles :: [Int]
triangles = scanl1 (+) [1..]
main = print . head $ filter (\i -> length (divisors i) > 500) triangles