Skip to content

Instantly share code, notes, and snippets.

View CarstenKoenig's full-sized avatar

Carsten König CarstenKoenig

View GitHub Profile
module Main where
import Data.List (foldl')
import Data.Char (toLower, isDigit)
data Move
= MoveUp
| MoveDown
| MoveLeft
| MoveRight

Run Suave on Linux

Step 1 - Install Forge

  • clone the forge-project git clone https://github.com/fsharp-editing/Forge.git
  • change directory cd Forge
  • run the build script ./build.sh

if all works out you should have a Forge.exe in ./temp/bin that you can call with mono (assuming you use mono)

@CarstenKoenig
CarstenKoenig / PoorUnionType.js
Created November 10, 2016 12:24
poor mans union type in noob javascript
function CaseA (value) {
return function(caseA, caseB) { return caseA(value); }
}
function CaseB (value) {
return function(caseA, caseB) { return caseA(value); }
}
function match (union, caseA, caseB) {
return union(caseA, caseB);
@CarstenKoenig
CarstenKoenig / PoorMans.hs
Created November 10, 2016 11:13
poor mans Union-Type
{-# LANGUAGE RankNTypes #-}
module PoorMans where
-- should be easy to translate into JS ... no types needed
newtype Union a b = MkUnion (forall c . (a -> c, b -> c) -> c)
valueA :: a -> Union a b
valueA a = MkUnion (\ (f, _) -> f a)
module Poly
fT : (img:Type->Type) -> Type
fT img = (a:Type) -> (a -> img a)
g : {a:Type} -> {b:Type} -> (img : Type -> Type) -> (fT img) -> a -> b -> (img a, img b)
g {a} {b} _ f x y = ((f a) x, (f b) y)
f1 : a -> List a
f1 x = [x]
@CarstenKoenig
CarstenKoenig / UnsafeValueVsUnsafeFunction.hs
Created July 18, 2016 08:26
just to show some simple things
module Unsafe where
import System.Random
import System.IO.Unsafe(unsafePerformIO)
generateUUID :: () -> String
generateUUID () = show $ unsafePerformIO (randomIO :: IO Int)
wuiPanel :: () -> IO String
wuiPanel () = do
@CarstenKoenig
CarstenKoenig / FizzBuzz.hs
Created July 3, 2016 14:15
monoid FizzBuzz
module FizzBuzz
(
fizzBuzz
) where
import Data.Maybe (fromMaybe)
fizzBuzz :: Integer -> String
fizzBuzz n = fromMaybe (show n) $ fizz n `mappend` buzz n
where fizz = maybeWord 3 "Fizz"
module HW06 where
import Prelude hiding (repeat)
import Data.List(intercalate)
data Stream a = Cons a (Stream a)
toList :: Stream a -> [a]
toList (Cons a s) = a : toList s
@CarstenKoenig
CarstenKoenig / santasprime.fs
Created December 23, 2015 13:10
F# advent 2015 - santas prime
// let's start with something easy: Chruch-encoded-Booleans:
type BoolC =
abstract apply : 'a -> 'a -> 'a
let trueC : BoolC =
{ new BoolC with member __.apply t _ = t }
let falseC : BoolC =
@CarstenKoenig
CarstenKoenig / Rooms.hs
Created November 8, 2015 12:42
enumerate rooms with persons with stars
module Rooms where
import Data.List (intercalate)
data Room = Room [Person]
data Person = Person [Star]
data Star = Star
instance Show Room where
show (Room ps) = "room: " ++ intercalate ", " (map show ps)