This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- short-circuiting folds | |
import Prelude hiding (foldl, foldr) | |
foldl :: (b -> a -> b) -> b -> [a] -> b | |
foldl f a [] = a | |
foldl f a (x:xs) = foldl f (f a x) xs | |
foldr :: (a -> b -> b) -> b -> [a] -> b | |
foldr f z [] = z |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data A = A1 | A2 deriving Show | |
data B = B1 | B2 | B3 deriving Show | |
type PairAB x = (A -> B -> x) -> x | |
pairAB :: A -> B -> PairAB x | |
pairAB a b g = g a b | |
fstAB :: PairAB A -> A -- ((A -> B -> A) -> A) -> A | |
fstAB p = p (\x y -> x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DeriveAnyClass #-} | |
{-# LANGUAGE DeriveGeneric #-} | |
{-# LANGUAGE TemplateHaskell #-} | |
module Database ( | |
Database, | |
Key, Value, | |
createDB, | |
get, set, | |
rcdata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DeriveAnyClass #-} | |
{-# LANGUAGE DeriveGeneric #-} | |
{-# LANGUAGE TemplateHaskell #-} | |
module Database ( | |
Database, | |
Key, Value, | |
createDB, | |
get, set, | |
rcdata, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE TemplateHaskell, DeriveDataTypeable, DeriveGeneric #-} | |
{-# LANGUAGE RecordWildCards #-} | |
{-# LANGUAGE LambdaCase #-} | |
import Control.Distributed.Process | |
hiding (Message, mask, finally, handleMessage, proxy) | |
import Control.Distributed.Process.Backend.SimpleLocalnet (Backend, findPeers, initializeBackend, newLocalNode) | |
import Control.Distributed.Process.Closure | |
import Control.Distributed.Process.Node (initRemoteTable, runProcess) | |
import Control.Concurrent.Async | |
import Control.Monad.IO.Class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List (unfoldr) | |
-- Recursive definition of binomial coefficient | |
-- Can take exponential time in n + k | |
-- Try binom_r 25 10 -- already takes several seconds | |
binom_r :: Int -> Int -> Integer | |
binom_r n 0 = 1 | |
binom_r n k | n == k = 1 | |
| otherwise = binom_r (n-1) (k-1) + binom_r (n-1) k |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env stack | |
-- stack script --resolver lts-14.9 --package=HExcel | |
import HExcel | |
main = do | |
wb <- workbookNew "buggy-dates.xls" | |
let props = mkDocProperties | |
{ docPropertiesTitle = "Buggy Dates" | |
, docPropertiesCompany = "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
{-# LANGUAGE TypeFamilies #-} | |
module Lib | |
( HasDummy | |
, Injectable | |
, Product | |
, Union | |
, pair |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resolver: lts-6.35 # need to set this to old resolver | |
flags: | |
parconc-examples: | |
distributed: true | |
accelerate: true | |
devil: true # need to set this to build repa-devil | |
extra-package-dbs: [] | |
packages: | |
- '.' | |
extra-deps: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- Derived from a program believed to be originally written by John | |
-- Launchbury, and incorporating the RSA algorithm which is in the | |
-- public domain. | |
-- | |
-- This is a rate-limiting version of https://github.com/simonmar/parconc-examples/blob/master/rsa-pipeline.hs, | |
-- as per the exercise on page 69 of Parallel and Concurrent Programming in Haskell. | |
-- Uses https://gist.github.com/lylek/58d9307431c9dbee6505bd588b8dfbc9 for the StreamFork library. |
NewerOlder