This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# | |
# vim:syntax=python:sw=4:ts=4:expandtab | |
import functools | |
def wrap(orig_func): | |
# now some funky python magic | |
@functools.wraps(orig_func) | |
def outer(new_func): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Tree a = Node (Tree a) (Tree a) | |
| Leaf a | |
deriving Show | |
instance Functor Tree where | |
fmap g (Leaf v) = Leaf (g v) | |
fmap g (Node l r) = Node (fmap g l) (fmap g r) | |
sampleTree :: Tree String | |
sampleTree = Node (Node (Leaf "hello") (Leaf "foo")) (Leaf "baar") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo(val a: Int, val b: String) { | |
private var _c: Int = 42 // fuer die meisten default | |
def c: Int = _c | |
def this(a: Int, b: String, c: Int) = { | |
this(a, b) | |
_c = c | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Foo[TC[_], V] | |
/* compilation error | |
* ----------------- | |
* view_bound_error.scala:11: error: type T takes type parameters | |
* def viewBound[T[V] <% Foo[T, V], V](value: T[V]) = value | |
* ^ | |
* one error found | |
*/ | |
def viewBound[T[V] <% Foo[T, V], V](value: T[V]) = value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- little helper function | |
-- f3 (f2 (f1 x)) == x -: f1 -: f2 -: f3 | |
(-:) x f = f x | |
-- our data structure | |
data Tree a = Empty | |
| Node (Tree a) a (Tree a) | |
deriving Show | |
-- a step on the way through our tree. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- little helper function | |
-- f3 (f2 (f1 x)) == x -: f1 -: f2 -: f3 | |
(-:) x f = f x | |
-- the list zipper simply split the list in two parts. | |
type ListZipper a = ([a], [a]) | |
makeListZipper :: [a] -> ListZipper a | |
makeListZipper l = (l, []) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Foldable as F | |
-- our data structure | |
data Tree a = Empty | |
| Node (Tree a) a (Tree a) | |
deriving Show | |
-- a step on the way through our tree. | |
-- either going to the left or to the right. | |
data Direction a = DLeft a (Tree a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- xmobar util to read temperature on lenovo notebooks | |
- | |
- usage: | |
- , Run Com "/home/fire/.xmonad/ibm_temp" ["40", "#B6B4B8", "red"] "temp" 10 | |
-} | |
import System( getArgs ) | |
import Data.Maybe | |
import Control.Monad | |
import Control.Applicative |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad.Reader | |
import Control.Monad.State | |
import Control.Monad.Writer | |
-- our monad transformer stack | |
-- a reader with an prefix string for the log | |
-- a state with the current value as integer | |
-- a writer to log the work done | |
-- all in a IO monad | |
type Prefix = String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | |
import Control.Monad.Reader | |
import Control.Monad.State | |
import Control.Monad.Writer | |
-- our monad transformer stack | |
-- a reader with an prefix string for the log | |
-- a state with the current value as integer | |
-- a writer to log the work done |
OlderNewer