Skip to content

Instantly share code, notes, and snippets.

My PL Shopping List
===================
- static types
- lightweight syntax for lambda expressions
- type annotations on any expression
- higher-kinded types
- monad comprehensions (for/do)
- applicative comprehensions (applicative do, idiom brackets)
- functor comprehensions
package demo.maps;
import java.util.HashMap;
import java.util.Map;
import static demo.maps.MapUtils.P.p;
public class MapUtils {
private MapUtils() {
@techtangents
techtangents / records.elm
Created April 25, 2015 00:07
record pattern matching example
type Pos2D = Pos2D { x : Int, y : Int }
area : Pos2D -> Int
area (Pos2D {x,y}) = x * y
module Namespacing2 where
type Pos2DU = { x :: Number, y :: Number }
area :: Pos2DU -> Number
area {x = x, y = y} = x * y
data Pos2DT = Pos2DT { x :: Number, y :: Number }
https://wiki.haskell.org/Typeclassopedia
Functor -> Applicative -> Monad
Apply -----^
https://github.com/purescript/purescript-control
Functor -> Apply -> Applicative -> Monad
-> Bind ----------^
package com.example;
public abstract class Either<A, B> {
public abstract <T> T fold(final F<A, T> af, final F<B, T> bf);
private Either(){}
public static <A, B> Either<A, B> a(final A a) {
return new Either<A, B>() {
Higher-kinded types in Java
===========================
If we consider that types classify values, then kinds classify types.
To use Haskell notation, simple java types are of kind * - the kind of types of values.
Generic types (e.g. List) are of kind * -> * - this is essentially a type-level
function - pass a type parameter A to the List type constructor and you get a List<A>.
Higher-kinded types are (basically) of kind (* -> *) -> *.
import java.util.function.Function;
public class Blah {
private Blah() {
}
static class A {
}
Proof of the functor laws for the Maybe functor
fmap :: (a -> b) -> Maybe a -> Maybe b
fmap f (Just x) = Just (f x)
fmap f Nothing = Nothing
Prove:
fmap id = id
Case 1: Just x
@techtangents
techtangents / FreeDom.purs
Last active June 17, 2017 03:54
FreeDom.purs
module FreeDom where
import Control.Monad.Free
import Control.Monad.Free.Trans
import DOM
import DOM.HTML
import DOM.HTML.Window
import DOM.Node.Node
import DOM.Node.Types
import Data.Array