This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// translated from http://www.haskellforall.com/2012/06/you-could-have-invented-free-monads.html | |
// we need our functor that will define the DSL more or less | |
type Command<'next> = | |
| Output of string * 'next | |
| Bell of 'next | |
| Done | |
// we need the fmap for the functor | |
let fmap f = function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Projektion | |
type Key = int | |
type Projection<'ev,'st,'res> = | |
{ | |
init : Key -> 'st | |
fold : 'st -> 'ev -> 'st | |
final : 'st -> 'res | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Movement = | |
| Left of int | |
| Right of int | |
type MovementState<'a> = Movement list -> Movement list * 'a | |
type MovementBuilder () = | |
member x.Zero () : MovementState<unit> = fun st -> (st, ()) | |
member __.Return x : MovementState<'a> = fun st -> (st, x) | |
member __.Bind(m: MovementState<'a>, f) = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Algorithmus | |
// (DE) http://ccd-school.de/coding-dojo/function-katas/russische-bauernmultiplikation/ | |
// (EN) https://en.wikipedia.org/wiki/Ancient_Egyptian_multiplication | |
let rec mul a b = | |
match a with | |
| 1 -> b | |
| a when a <= 0 -> 0 | |
| a when x % 2 = 0 -> mul (a/2) (b*2) | |
| a -> mul (a/2) (b*2) + b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{---------------------------------------------------------------------- | |
- CCD Function Kata | |
- Russische Bauernmultiplikation | |
- | |
- siehe: http://ccd-school.de/coding-dojo/function-katas/russische-bauernmultiplikation/ | |
- | |
- | |
- Erklärung: | |
- --------- | |
- wie das funktioniert versteht am am einfachsten, wenn man sich die linke |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(*********************************************************************** | |
* CCD Function Kata | |
* Russische Bauernmultiplikation | |
* | |
* siehe: http://ccd-school.de/coding-dojo/function-katas/russische-bauernmultiplikation/ | |
* | |
* | |
* Erklärung: | |
* --------- | |
* wie das funktioniert versteht am am einfachsten, wenn man sich die linke |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(***************************************************************************************** | |
* Task: | |
* ===== | |
* | |
* There is a string which may contain asterisks. Each asterisk must be replaced by | |
* a 0 or 1 and then all possible output combinations must be printed out. | |
* | |
* For example the strings | |
* | |
* a*b must produce two outputs a0b and a1b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module EightQ where | |
import Control.Monad (foldM) | |
type Queen = (Int,Int) | |
{----------------------------------------------------------------------- | |
Questions: | |
- would you consider `queens` readable? | |
- what about understanding? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Matrizen | |
import Data.Vect | |
Matrix : (Nat, Nat) -> Type -> Type | |
Matrix (n,m) a = Vect n (Vect m a) | |
scalProd : Num a => Vect n a -> Vect n a -> a | |
scalProd xs ys = sum $ zipWith (*) xs ys |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module List = | |
type Item = { value : int; next : List } | |
and List = Item option ref | |
let empty : List = ref None | |
let singleton x = { value = x; next = ref None } | |
let rec append x l = | |
let item = singleton x |