##Monads for functional programming (in Elm)
Adaptation of the examples in Philip Wadler's paper "Monads for functional programming" for the Elm language.
These examples can easily be tried out on the online elm playground: http://elm-lang.org/try
INSTALL_URL="https://releases.nixos.org/nix/nix-2.3.10/install" | |
# Install Nix (package manager) | |
if [[ "$OSTYPE" == "linux-gnu"* ]]; then | |
sh -c "$(curl -L $INSTALL_URL)" | |
elif [[ "$OSTYPE" == "darwin"* ]]; then | |
sh -c "$(curl -L $INSTALL_URL)" --darwin-use-unencrypted-nix-store-volume | |
else | |
echo "Unsupported platform :(" | |
return |
// No TypeScript, but statically typed | |
let add = (a, b) => a + b; |
open Belt.Result; | |
type options; | |
module Stdio: { | |
type t = pri string; | |
[@bs.inline "inherit"] | |
let inherit_: t; |
convert "$@" +dither -colors 5 -unique-colors txt: | head -n 2 | tail -n 1 | awk '{ print $3 }' |
defaults read com.apple.BluetoothAudioAgent > ~/com.apple.BluetoothAudioAgent.defaults.txt | |
defaults write com.apple.BluetoothAudioAgent "Apple Bitpool Max (editable)" 80 | |
defaults write com.apple.BluetoothAudioAgent "Apple Bitpool Min (editable)" 80 | |
defaults write com.apple.BluetoothAudioAgent "Apple Initial Bitpool (editable)" 80 | |
defaults write com.apple.BluetoothAudioAgent "Apple Initial Bitpool Min (editable)" 80 | |
defaults write com.apple.BluetoothAudioAgent "Negotiated Bitpool" 80 | |
defaults write com.apple.BluetoothAudioAgent "Negotiated Bitpool Max" 80 | |
defaults write com.apple.BluetoothAudioAgent "Negotiated Bitpool Min" 80 |
<!DOCTYPE html><script src="https://jspm.io/[email protected]"></script><script>System.config({transpiler: "babel"});System.import("./index.js");</script><body></body></html> |
import React from 'react' | |
import ReactDOM from 'react-dom' | |
const Hello = ({name}) => <h1>Hello {name}!</h1> | |
ReactDOM.render( | |
<Hello name={"vjeux"}/>, | |
document.body.appendChild(document.createElement("div")) | |
) |
##Monads for functional programming (in Elm)
Adaptation of the examples in Philip Wadler's paper "Monads for functional programming" for the Elm language.
These examples can easily be tried out on the online elm playground: http://elm-lang.org/try
let map = (fn,[head, ...tail]) => head === undefined | |
? [] | |
: [fn(head), ...map(fn,tail)] | |
console.log("map(x=>x+1,[1,2,3,4]) :",map(x=>x+1,[1,2,3,4])) | |
let filter = (predicate, [head, ...tail]) => head === undefined | |
? [] | |
: predicate(head) | |
? [head, ...filter(predicate, tail)] |
def unfold[A,S](initial: S)(generateNext: S => Option[(A, S)]): Stream[A] = | |
generateNext(initial) match { | |
case Some((first, next)) => cons(first, unfold(next)(generateNext)) | |
case None => empty | |
} | |
val fibs = | |
unfold((0,1)) { | |
case (f0, f1) => Some((f0, (f1, f0+f1))) | |
} |