- Setup the binary cache -
cachix use mpickering
This is a term that performs modulo 32 addition on two 32-bit binary numbers efficiently on the abstract algorithm.
On this example, I compute 279739872 + 496122620 = 775862492
.
binSize= 32
binZero= (binSize r.a.b.c.(a r) a.b.c.c)
binSucc= (binSize r.x.a.b.c.(x b x.(a (r x)) c) a.a)
binFold= x.a.b.c.(binSize r.x.(x x.f.(a (f x)) x.f.(b (f x)) f.c r) a.c x)
binToNat= (binSize r.n.x.(x x.f.(f x) x.f.(add n (f x)) f.0 (r (mul 2 n))) n.x.0 1)
The original code (~7.2s on my laptop).
import System.Random
import System.CPUTime
rainfall :: [Int] -> Int
rainfall xs = sum (zipWith (-) mins xs)
{-# LANGUAGE OverloadedStrings #-} | |
{-# OPTIONS_GHC -Wall #-} | |
-- Set your font to a monospace font which makes this character the same as the line-height: │ | |
-- | |
-- Otherwise, you'll see an ugly gap between connected lines if the | |
-- line-height of the font is high. | |
-- | |
-- Example fonts: | |
-- |
{-# LANGUAGE TemplateHaskell #-} | |
module Lens where | |
import Control.Lens | |
import Data.Monoid (First, (<>)) | |
data FooBar = | |
Foo (Either Int Bool) | |
| Bar (Maybe Bool) |
#!/usr/bin/env bash | |
if [[ -z "$1" ]]; then | |
echo "No filter given, abort" | |
exit 1 | |
fi | |
tmp=$(mktemp -d) | |
jq="$tmp/jq" |
{-# LANGUAGE OverloadedStrings #-} | |
module Main where | |
import Network.Wai (pathInfo, Request, requestMethod, Response, responseLBS, ResponseReceived) | |
import Network.Wai.Handler.Warp (run) | |
import Network.HTTP.Types (status200, status401) | |
-- note: type Application = Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived | |
application :: Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived |
This is intended as a reply to https://ro-che.info/articles/2017-06-12-friendly-contributing-policies, but I don't really want it to be a blog post (it's not the right level for my blog), and that blog doesn't have comments, and I don't want to mis-express myself in 120 characters or whatever. So here goes a gist :)
Firstly, as to the talk, the context was read around the project, and figure out if it will suit you. I am deliberately quoting haskell-src-exts out of context, and deliberately not saying where either quote came from. I appreciate the full policy is much more welcoming than that one snippet would imply.
However, when I wanted to find an unfriendly contributing policy, I immediately thought of haskell-src-exts. I do genuinely find the document, as a whole, quite unwelcoming. I appreciate that languages sound different to native speakers, and it didn't stop me contributing, but it did give me pause. Whether a document is friendly or not is a feeling, and so by explaining why I have that feeling
{-# LANGUAGE TemplateHaskell #-} | |
-- | For when you have a record that doesn't have lenses derived for | |
-- it and you need a lens, just use @$(lens 'thefield)@ and away you go. | |
module Control.Lens.FieldTH where | |
import Language.Haskell.TH | |
lens :: Name -> Q Exp | |
lens name = do | |
[|\f r -> | |
fmap | |
$(lamE |