Skip to content

Instantly share code, notes, and snippets.

View exterm's full-sized avatar

Philip Theus (prev. Mueller) exterm

View GitHub Profile
@exterm
exterm / 1_types.hs
Last active December 13, 2015 21:38
Type System restrictions: Haskell forces constructors to be unambigous, erlang (dialyzer) doesn't care.
data T1 = Bernd | Uwe
data T2 = Bernd | Flo
@exterm
exterm / inference.hs
Last active December 14, 2015 03:59
Haskell underestimates parameter types and overestimates return types.
and _ False = False
and False _ = False
and _ _ = True
-- inferred type: Bool -> Bool -> Bool
-- underestimated parameter type: the function would also work called like this:
and 42 False
-- and return False; the type checker throws an error for this though.
and' _ False = 0
@exterm
exterm / stringbool.rb
Created March 5, 2013 01:40
simple type problem in ruby
irb(main):001:0> "false" ? true : false
(irb):1: warning: string literal in condition
=> true
# no warning if string is not a literal
@exterm
exterm / 1_class.py
Created March 5, 2013 21:45
Translating Python to Haskell, keeping core concepts
# A simple class in Python
class car():
# The __init__ method
def __init__(self, color):
self.color = color
# The color method
def color(self):
return self.color
@exterm
exterm / GADTs.hs
Created March 6, 2013 19:53
Example for Generalised Algebraic Datatypes in Haskell Used to create a safe list type
data Safe a = Safe a
data NotSafe = NotSafe
data SafeList a b where
Nil :: SafeList a NotSafe
Cons :: a -> SafeList a b -> SafeList a (Safe b)
safeHead :: SafeList a (Safe b) -> a
safeHead (Cons x _) = x
-- safeHead Nil = ???
@exterm
exterm / phantom.hs
Created March 6, 2013 20:56
Example for Phantom Types in Haskell
data PList a b = Nil
| Cons a (PList a b)
test :: PList Int String
test = Cons 3 $ Cons 2 $ Cons 1 Nil
data Foo = Foo
test2 :: PList Int Foo
test2 = Cons 3 $ Cons 2 $ Cons 1 Nil
@exterm
exterm / vectors.agda
Created March 6, 2013 21:33
Example for Dependent Types in Agda
data Vec (A : Set) : Nat -> Set where
[] : Vec A zero
_::_ : {n : Nat} -> A -> Vec A n -> Vec A (succ n)
head : {A : Set} {n : Nat} -> Vec A (succ n) -> A
head (x :: _) = x
@exterm
exterm / error.hs
Last active December 14, 2015 14:49
Provoke compile time errors in liquid Haskell
{-@ error2 :: {v: String | false } -> a @-}
error2 :: String -> a
error2 = error
-- a program using this function typechecks exactly when LiquidHaskell can prove that the
-- function error2 is never called.
@exterm
exterm / multiclause.erl
Last active December 15, 2015 02:49
Interesting example for multi-clause type spec in erlang dialyzer.
%% multi clause function type spec
-spec plus(integer(), float()) -> float();
(float(), integer()) -> float();
(float(), float()) -> float();
(integer(), integer()) -> integer().
plus(A,B) ->
A + B.
testp() ->
@exterm
exterm / PKGBUILD
Created April 10, 2013 12:31
updated emacs-haml-mode-git PKGBUILD
# Contributor: Moritz Heidkamp <moritz@twoticketsplease.de>
pkgname=emacs-haml-mode-git
pkgver=20110912
pkgrel=1
pkgdesc="An emacs mode for editing HAML code."
arch=("i686" "x86_64")
url="http://haml-lang.com/"
license=('MIT')
makedepends=('git')
provides=(emacs-haml-mode)