Skip to content

Instantly share code, notes, and snippets.

@erantapaa
erantapaa / Main.hs
Last active July 31, 2017 19:04
pattern synonyms / views and regexs
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms, ViewPatterns #-}
{-# LANGUAGE QuasiQuotes, FlexibleContexts #-}
-- Example of using PatternSynonyms and ViewPatterns to simplify
-- the parsing of a text file with regexs.
module Heavy where
import Data.Monoid
@erantapaa
erantapaa / F16.hs
Last active August 27, 2016 14:09
Implementation of GF(2^16)
{-# LANGUAGE BangPatterns #-}
module F16 where
import Data.Int
import Data.Bits
import Data.List
import Data.Ratio
import Numeric
import Data.Ord
@erantapaa
erantapaa / README.md
Last active August 18, 2016 00:34
Using stack for interactive ghc sessions

Recipe for installing stack and using it interactively.

  1. Install stack -- https://docs.haskellstack.org/en/stable/README/
  2. Choose a resolver - e.g. lts-6.11
  3. Edit ~/.stack/global-project/stack.yaml and set resolver: to the value selected in step 3.
  4. Run: stack setup

Now when you want to run ghci use:

@erantapaa
erantapaa / bind-return
Created August 16, 2016 03:07
instances of ... <- return ...
:accelerate-0.15.1.0/Data/Array/Accelerate/Interpreter.hs
387;14 9: y <- return . fromElt $ ain i
412;14 9: y <- return . fromElt $ ain (i-1)
452;14 9: y <- return . fromElt $ ain (n-i)
475;14 9: y <- return . fromElt $ ain (n-i-1)
537;18 9: x <- return . fromElt $ ain i
:ACME-0.0.0.1/Acme/Cipher.hs
105;17 9: (init1, stdgen) <- return (randomLetter stdgen)
106;17 9: (init2, stdgen) <- return (randomLetter stdgen)
@erantapaa
erantapaa / Example.hs
Created August 15, 2016 15:06
UseProvidedHandle version of sourceProcessWithStream
#!/usr/bin/env stack
{- stack runghc --resolver lts-6.0
--package streaming-commons
--package conduit
--package conduit-extra
-}
{-# LANGUAGE OverloadedStrings #-}
import StreamExtra
@erantapaa
erantapaa / hlist.hs
Created August 3, 2016 15:19
to/from HList
{-# LANGUAGE TypeFamilies, DataKinds, ScopedTypeVariables, RankNTypes, GADTs, TypeOperators #-}
module HListFL where
data Nat = Z | S Nat
data Natty n where
Zy :: Natty 'Z
Sy :: Natty n -> Natty ('S n)
@erantapaa
erantapaa / ctype_async_raise.py
Created July 18, 2016 05:07 — forked from liuw/ctype_async_raise.py
Nasty hack to raise exception for other threads
#!/usr/bin/env python
# liuw
# Nasty hack to raise exception for other threads
import ctypes # Calm down, this has become standard library since 2.5
import threading
import time
NULL = 0
@erantapaa
erantapaa / Dummy.hs
Created July 13, 2016 18:51
dummy persistent connection
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.Text.IO as T
import Database.Persist.Sql
import Data.Monoid
import Data.Conduit
import Data.Acquire
import Data.IORef
import qualified Data.Map as Map
import qualified Data.Conduit.List as CL
@erantapaa
erantapaa / ghci hacks
Created June 7, 2016 23:07
getting more out of ghci
Source: https://mail.haskell.org/pipermail/haskell-cafe/2007-September/032260.html
[Haskell-cafe] getting more out of ghci [longish]
Claus Reinke claus.reinke at talk21.com
Tue Sep 25 11:52:23 EDT 2007
== intro
no, i'm not talking about using a nice frontend to ghci, with added
@erantapaa
erantapaa / xy.hs
Created June 5, 2016 08:11
pipes - break lines at a two character delimiter
{-# LANGUAGE OverloadedStrings, NoMonomorphismRestriction #-}
{-# LANGUAGE MultiWayIf, RankNTypes #-}
import Pipes
import qualified Pipes.Prelude as PP
import qualified Pipes.Group as PG
import qualified Pipes.ByteString as PB
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString as BS0
import Lens.Family (view, over, (^.))