Skip to content

Instantly share code, notes, and snippets.

Carsten CarstenKoenig

Block or report user

Report or block CarstenKoenig

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Flatten.purs
module Main where
import Prelude
import Data.Symbol (class IsSymbol, SProxy(..))
import Effect (Effect)
import Effect.Console (log)
import Prim.Row as Row
import Prim.RowList (kind RowList, Nil, Cons, class RowToList)
import Record (get)
@CarstenKoenig
CarstenKoenig / Riddle.hs
Created Jul 7, 2018
nice Haskell Type - Riddle
View Riddle.hs
{-# LANGUAGE RankNTypes, DeriveFunctor #-}
module Riddle where
type T a b c = forall f . Functor f => (a -> f b) -> f c
to :: (a, b -> c) -> T a b c
to (a, b_c) f = fmap b_c (f a)
View Pruefsumme.hs
module Main where
import Data.List (unfoldr)
main =
putStrLn $ "Prüfe Rechnungsnummer 4711: " ++ show (pruefsummeFuerRechnungsNummern 4711)
pruefsummeFuerNetzwerkAdressen =
pruefsumme [5,1] 9 digitsRightToLeft
@CarstenKoenig
CarstenKoenig / VectMap.hs
Created May 30, 2018
Vector map in Haskell
View VectMap.hs
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
module VectMap where
import GHC.TypeLits
data Vect (n :: Nat) a where
@CarstenKoenig
CarstenKoenig / pulp12
Created May 27, 2018
Run Purescript 0.12 parallel to 0.17
View pulp12
#!/bin/bash
cp ~/.local/bin/purescript/v0.12/purs ~/.local/bin/purs
pulp $@
rm ~/.local/bin/purs
# - still got purs 0.11.7 from npm
# - have current purescript/purs compiled/installed with stack
# - move the version somewhere (I opted into the path above)
# - have .local/bin before your npm installed bins in your PATH
@CarstenKoenig
CarstenKoenig / Dockerfile
Last active Apr 16, 2018
temporärer Haskell-Build Container
View Dockerfile
FROM fpco/stack-build:lts-11 as builder
ENV BUILD=/app
RUN mkdir -p $BUILD
COPY . $BUILD
WORKDIR $BUILD
RUN stack install --local-bin-path ./dist
FROM ubuntu:16.04
RUN apt-get update
RUN apt-get install --yes libgmp-dev
@CarstenKoenig
CarstenKoenig / Leibniz.hs
Created Mar 20, 2018
simulating GADTs with Leibniz equality
View Leibniz.hs
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
module Leibniz where
-- WANT this without GADTS!:
data Form res where
FInt :: Int -> Form Int
FAdd :: Form Int -> Form Int -> Form Int
FNull :: Form Int -> Form Bool
@CarstenKoenig
CarstenKoenig / Parser.hs
Created Mar 13, 2018
baby ParserComp Lib
View Parser.hs
{-# LANGUAGE LambdaCase #-}
module Parser
( Parser
, parse
, Parser.fail
, succeed
, choose
, char
, digit
@CarstenKoenig
CarstenKoenig / MontyHall.fs
Created Feb 22, 2018
Monty-Hall with Probability-Monad in F#
View MontyHall.fs
type Probability = double
type Distribution<'a> = ('a * Probability) list
type Event<'a> = 'a -> bool
let printDistribution (v : Distribution<'a>) =
let negate x = -x
v |> List.sortBy (snd >> negate) |> List.iter (fun (a,p) -> printfn "%A: %.2f%%" a (p * 100.0))
let sure (a : 'a) : Distribution<'a> =
[a, 1.0]
@CarstenKoenig
CarstenKoenig / Hylo.fs
Last active Feb 19, 2018
Factorial using a Hylomorphism in F#
View Hylo.fs
type List<'i,'r> = Nil | Cons of 'i*'r
type FixList<'i> = FixList of List<'i,FixList<'i>>
let rec fmap (f : 'a -> 'b) (l : List<'i,'a>) : List<'i,'b> =
match l with
| Nil -> Nil
| Cons (x, tail) -> Cons (x, f tail)
// you can express hylo directly without using ana and cata (by either following the
You can’t perform that action at this time.