Skip to content

Instantly share code, notes, and snippets.

View jw3126's full-sized avatar

Jan Weidner jw3126

  • Freiburg, Germany
View GitHub Profile
module M
export @esc_none, @esc_all, @esc_args, @esc_args_impl
macro esc_none(x, y)
impl(x,y)
end
macro esc_all(x,y)
esc(impl(x,y))
end
@jw3126
jw3126 / SIMDmedian.jl
Last active October 13, 2017 11:56
SIMD median
using SIMD
Base.@pure simdwidth(::Type{T}) where {T} = Int(256/8/sizeof(T))
@inline function median3(a,b,c)
max(min(a,b), min(c,max(a,b)))
end
@inline function median5(a,b,c,d,e)
# https://stackoverflow.com/questions/480960/code-to-calculate-median-of-five-in-c-sharp
f=max(min(a,b),min(c,d))
@jw3126
jw3126 / supress.hs
Created August 6, 2017 19:03
Mapping from IO type to a "pure" type
-- we can define functions that discard IO
io :: IO Int
io = print "wehaa" >> return 17
supress :: IO Int -> Int
supress _ = 42
supress io
@jw3126
jw3126 / Interpreter.hs
Last active August 5, 2017 20:24
Interpreter in haskell that can store and retrieve variables
import Data.Map as Map
import Data.Map
import Control.Monad.State.Lazy
import Control.Monad
data Expr = ExInteger Integer
| ExSymbol String
| ExBinding String Expr deriving (Show)
type Errorful t = Either String t