Skip to content

Instantly share code, notes, and snippets.

View CarstenKoenig's full-sized avatar

Carsten König CarstenKoenig

View GitHub Profile
@CarstenKoenig
CarstenKoenig / Solution.hs
Created December 21, 2022 07:23
Advent of Code 2022 - Day 21
module Y2022.Day21.Solution where
import CommonParsers (Parser, nameP, numberP, runParser)
import Data.List (nub)
import Data.Map.Lazy (Map)
import qualified Data.Map.Lazy as Map
import qualified Text.Megaparsec as P
import qualified Text.Megaparsec.Char as PC
yearNr :: Int
@CarstenKoenig
CarstenKoenig / Solution.hs
Created December 19, 2022 11:05
Advent of Code 2022 - Day 19
{-# LANGUAGE BangPatterns #-}
-- Description : Advent of Code - 2022 / Tag 19
--
-- see [Advent of Code 2022 - day 19](https://adventofcode.com/2022/day/19)
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
{-# OPTIONS_GHC -Wno-name-shadowing #-}
module Y2022.Day19.Solution where
import CommonParsers (Parser, numberP, runParser)
@CarstenKoenig
CarstenKoenig / Flatten.purs
Created August 23, 2018 12:57
Flatten record
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 July 7, 2018 20:31
nice Haskell Type - Riddle
{-# 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)
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 15:26
Vector map in Haskell
{-# 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 11:31
Run Purescript 0.12 parallel to 0.17
#!/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 April 16, 2018 12:34
temporärer Haskell-Build Container
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 March 20, 2018 12:22
simulating GADTs with Leibniz equality
{-# 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 March 13, 2018 10:09
baby ParserComp Lib
{-# LANGUAGE LambdaCase #-}
module Parser
( Parser
, parse
, Parser.fail
, succeed
, choose
, char
, digit