Skip to content

Instantly share code, notes, and snippets.

{-# LANGUAGE DataKinds, TypeFamilies, KindSignatures, TypeOperators,
GADTs, FlexibleInstances, FlexibleContexts, UndecidableInstances,
MultiParamTypeClasses, FunctionalDependencies #-}
module HeteroList
( HList (HNil, (:::))
, hhead, htail
, hinit, hlast
, hlength, hnull
, hreverse, (+++)
import Control.Monad
import Data.Maybe
import qualified Data.Map as Map
-- Typen zur Programmbeschreibung
data Source = Reg Int | Val Integer deriving (Show, Eq)
type Instruction = (Source, Source, Int, Int)
type Program = [Instruction]
-- Typen für das Runtimesystem
@fatho
fatho / gist:5653604
Created May 26, 2013 18:25
A quad tree.
module QuadTree
( Point, Size, Rect(Rect), Item(Item), QuadTree, Quad
, empty, insert, delete, filterTree, query, stats
) where
import qualified Data.List as L
import qualified Debug.Trace as Dbg
-------------------------------------------------------------------------------
-- TYPES
@fatho
fatho / gist:5670278
Last active December 17, 2015 20:49
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
import Prelude hiding ((++))
import qualified Prelude as P
class ListLike a where
(++) :: a b -> a b -> a b
(<:) :: b -> a b -> a b
(>:) :: a b -> b -> a b
nil :: a b
import Data.List
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as M
data Literal = AtomL String | IntL Int | DoubleL Double deriving (Eq)
data Term = Functor String [Term]
| Atomic Literal
| Variable String deriving (Eq)
@fatho
fatho / gist:6661270
Last active December 23, 2015 16:19 — forked from zrho/gist:6660923
import Control.Monad.IO.Class
newtype SchadeT m a = SchadeT { runSchade :: m a }
type SchadeM = SchadeT IO
instance Monad m => Monad (SchadeT m) where
return x = SchadeT $ return x
m >>= f = SchadeT $ runSchade m >>= (runSchade . f)
schade :: MonadIO m => SchadeT m ()
@fatho
fatho / gist:6735951
Last active December 24, 2015 03:09
{-# LANGUAGE TemplateHaskell #-}
module DeriveBinary where
import Language.Haskell.TH
import Language.Haskell.TH.Syntax
import Control.Monad
import Data.Binary
import Data.Int
@fatho
fatho / gist:8269773
Last active January 2, 2016 07:28
Haskell-Features in C++
//============================================================================
// Name : FunctionalCPP.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <functional>
#include <iostream>
#include <string>
@fatho
fatho / ConduitListT.hs
Last active August 29, 2015 14:06
ListT using conduit
import Control.Applicative
import Control.Monad
import Data.Conduit
import qualified Data.Conduit.List as CL
newtype ListT m a = ListT { runListT :: Producer m a }
instance (Monad m) => Functor (ListT m) where
fmap f (ListT l) = ListT (l $= CL.map f)