Skip to content

Instantly share code, notes, and snippets.

@electroCutie
electroCutie / ListConsumer.hs
Last active September 7, 2018 13:01
A Monad for taking values from a list in a safe way
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Data.ListConsumer (
ListConsumer, takeN, peekN, dropN, takeAll, takeAny, runL, runFoldableL
) where
import Control.Applicative
import Control.Arrow
import Control.Monad

Keybase proof

I hereby claim:

  • I am electrocutie on github.
  • I am electrocutie (https://keybase.io/electrocutie) on keybase.
  • I have a public key ASDKaTj1zKxT1O4hYIKcLIMtpD_dl4AYTbwsNPyE6MgmNgo

To claim this, I am signing this object:

sieve :: [Int]
sieve = 2 : ([3,5..] >>= test sieve)
where
test p c = test' p c $ floor . sqrt . fromIntegral $ c
test' (p:ps) c lim --primes and candiate
| p > lim = [c]
| rem c p == 0 = []
| otherwise = test' ps c lim