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 / 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 / 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 / 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 / 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 / 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 / Decoupling.hs
Last active December 10, 2015 19:39
Showing that a function that depends only on a single attribute of a map like data structure is also possible with static records/structs. This allows adding/removing attributes from the record without modification of the all_members function.
data Project = Project {
projId :: String,
projKind :: ProjectKind,
projDescription :: String,
projBudget :: Int,
projTeam :: [Person]
}
all_members :: [Project] -> [Person]
all_members projects = concat $ map projTeam projects
@exterm
exterm / mystery.rb
Created July 26, 2012 08:08
Clean Code.
def nb_lines(width, text)
text = "" if text.nil?
cw = @CurrentFont['cw']
width = @w - @rMargin - @x if (width == 0)
wmax = (width - 2 * @cMargin) * 1000 / @FontSize
s = text.gsub("\r", '')
nb = s.length
nb -= 1 if nb > 0 && s[nb-1] == "\n"
sep = -1
i, j, l = 0, 0, 0
@exterm
exterm / gist:2160644
Created March 22, 2012 17:39
project layout
.
├── deps
│ └── lager
├── disco
│ ├── ebin
│ └── src
├── launcher
│ ├── ebin
│ └── src
├── main.config
@exterm
exterm / rebar.config
Created March 22, 2012 17:29
rebar configuration
% documentation for rebar.config: https://github.com/basho/rebar/blob/master/rebar.config.sample
{sub_dirs, ["launcher", "disco"]}.
{erl_opts, [debug_info, fail_on_warning, parse_transform, lager_transform]}.
{require_otp_vsn, "R14"}.
{deps,
[lager,
@exterm
exterm / Xorg.0.log
Created March 19, 2012 13:20
problem with arch startup
[ 19.863]
X.Org X Server 1.12.0
Release Date: 2012-03-04
[ 19.863] X Protocol Version 11, Revision 0
[ 19.863] Build Operating System: Linux 3.2.9-1-ARCH i686
[ 19.863] Current Operating System: Linux t41 3.2.11-1-ARCH #1 SMP PREEMPT Thu Mar 15 09:16:03 UTC 2012 i686
[ 19.863] Kernel command line: root=/dev/disk/by-label/linux_root ro
[ 19.863] Build Date: 05 March 2012 06:02:28AM
[ 19.863]
[ 19.863] Current version of pixman: 0.24.4