Skip to content

Instantly share code, notes, and snippets.

@sebfisch
sebfisch / jobs.markdown
Last active August 29, 2015 14:14
Implementation of the Jobs Puzzle in Curry

Implementation of the Jobs Puzzle in Curry

by Sebastian Fischer, January 2015

Verbal problem description

There are four people: Roberta, Thelma, Steve, and Pete.

@sebfisch
sebfisch / gist:158634
Created July 30, 2009 09:40
Simple solver for the n-queens problem in Curry
-- Simple solver for the n-queens problem in Curry.
--
-- A placement is represented as permutation of [1..n], each list
-- element represents the placement of a queen in the column
-- corresponding to its index.
import Integer ( abs )
-- Solutions are computed using a lazy generate-and-test approach:
-- candidate solutions are created lazily and admissible solutions
@sebfisch
sebfisch / gist:158635
Created July 30, 2009 09:41
Efficient solver for the n-queens problem in Curry
-- Efficient solver for the n-queens problem in Curry.
--
-- A placement is represented as permutation of [1..n], each list
-- element represents the placement of a queen in the column
-- corresponding to its index.
-- The implementation uses a finite domain constraint solver which is
-- available in the Curry system PAKCS.
--
import CLPFD
@sebfisch
sebfisch / etc.hs
Created August 28, 2009 13:19
Experiments with eval-time choice annotations for Curry
-- This snippet simulates naive dictionary passing for Curry type
-- classes using the explicit-sharing package for functional logic
-- programming in Haskell.
--
-- It defines a dictionary for the class
--
-- class Arb a where arb :: a
--
-- and a corresponding instance for the type Bool
--
@sebfisch
sebfisch / re2.cpp
Created July 24, 2010 08:36
C++ program that matches a regular expression using Google's re2 library
#include <iostream>
#include <string>
#include <re2/re2.h>
using namespace std;
using namespace re2;
int main(int argc, char* args[]) {
// not syncing C++ and C I/O is faster with simple matchings
ios_base::sync_with_stdio(false);
@sebfisch
sebfisch / gist:894311
Created March 30, 2011 12:32
Removes window decoration in tiling Bluetile layouts.
diff --git a/bluetile.cabal b/bluetile.cabal
index 5ccc294..fd358e6 100644
--- a/bluetile.cabal
+++ b/bluetile.cabal
@@ -1,5 +1,5 @@
Name: bluetile
-Version: 0.5.3
+Version: 0.5.3.1
homepage: http://www.bluetile.org/
synopsis: full-featured tiling for the GNOME desktop environment
@sebfisch
sebfisch / gist:921469
Created April 15, 2011 09:44
Collatz Memoization in Haskell
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
import Data.Function ( fix )
import Data.MemoTrie -- from package MemoTrie
import Data.MemoCombinators -- from package data-memocombinators
main :: IO ()
main =
-- without caching
@sebfisch
sebfisch / GenericFoldableTraversable.hs
Created July 30, 2011 01:15
Generic implementation of Foldable and Traversable instances
{-# LANGUAGE TypeFamilies, TypeOperators, FlexibleContexts #-}
module GenericFoldableTraversable where
import Data.Monoid ( Monoid, mappend, mempty )
import Data.Foldable ( Foldable, foldMap )
import Control.Applicative ( Applicative, pure, (<*>) )
import Data.Traversable ( Traversable, traverse )
@sebfisch
sebfisch / ArrowVsApplicative.hs
Created July 31, 2011 14:43
Comparison of Arrow and Applicative classes by implementing file IO
{-
example from
http://blog.downstairspeople.org/2010/06/14/a-brutal-introduction-to-arrows/
rewritten using Applicative instance from
http://cdsmith.wordpress.com/2011/07/30/arrow-category-applicative-part-i/
@sebfisch
sebfisch / interp.idr
Created August 17, 2011 06:47
Type-safe Interpreter in Idris
tyFun : Set -> Set -> Set;
tyFun A T = A -> T;
using (G:Vect Set n) {
data Expr : Vect Set n -> Set -> Set where
Var : (i:Fin n) -> Expr G (vlookup i G)
| Val : T -> Expr G T
| Lam : Expr (A::G) T -> Expr G (tyFun A T) -- using `A -> T` directly fails
| App : Expr G (A -> T) -> Expr G A -> Expr G T