Instantly share code, notes, and snippets.

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)
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
View VectMap.hs
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
module VectMap where
import GHC.TypeLits
data Vect (n :: Nat) a where
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
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
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
View Parser.hs
{-# LANGUAGE LambdaCase #-}
module Parser
( Parser
, parse
, Parser.fail
, succeed
, choose
, char
, digit
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]
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