As we discussed in a previous article, one of the things we can do with a function is to call it with fewer arguments than it is expecting. This will result in a new function where the arguments we did provide are bound to values, and the reminding arguments are still expected as parameters. Since we apply the function to only some of its arguments, we call this technique partial application.
Let's see how this works in Elm:
-- A simple function, adding together two arguments.
-- If you find the type signature confusing, don't worry
-- about that for now.
Hi there, and welcome to this advent calendar! While you wait for Christmas, we'll provide you with an article related to Functional Programming (FP) each day until December 24 🎅
We will try to tackle a wide range of topics. We will cover a few "classic" FP-concepts, both basic and more advanced. We also aim to have some articles with a more practical focus. Some posts will be intended for beginners and some will have a more experienced audience in mind. So if a particular article isn't for you, hopefully the next one will be!
To get the show on the road, lets start out by answering the following question:
God oppgave-drevet tutorial som lærer god forståelse av hvordan Decoders fungerer. Kort bloggpost om motivasjonen for tutorialen her
Som programmerere, hvordan kommer hverdagen vår til å se ut i fremtiden? Det er spørsmålet vi forsøker å besvare på Future Programming Workshop, en event som arrangeres dagen før StrangeLoop 2015.
Som arrangøren formulerte det innledningsvis, "at StrangeLoop you'll see a lot of stuff that actually works, but what about five or ten years from now?" Vi forsøker vi å løfte blikket for å få et glimt av hva som rører seg på horisonten.
Hvis vi myser litt, så kan dagens temaer grovt deles inn i to kategorier:
import re | |
from flask import Flask, request | |
app = Flask(__name__) | |
@app.route('/', endpoint='index') | |
def index(): | |
question = request.args.get("q", "").partition(": ")[2] | |
answer = "the answer" | |
print "\nQ: %s?\nA: %s" % (question, answer) |
from itertools import cycle, islice, izip, imap | |
fizz = cycle([""]*2 + ["fizz"]) | |
buzz = cycle([""]*4 + ["buzz"]) | |
fizzbuzz = imap(lambda (i, x): x[0]+x[1] or (i+1), enumerate(izip(fizz,buzz))) | |
print list(islice(fizzbuzz, 100)) |
(* University of Washington, Programming Languages, Homework 7 | |
Based on hw7testsprovided.sml *) | |
use "hw7.sml"; | |
use "testing.sml"; (* Requires https://github.com/kvalle/sml-testing to run! *) | |
open SmlTests; | |
fun real_equal(x,y) = Real.compare(x,y) = General.EQUAL; |
import re | |
from flask import Flask, request | |
app = Flask(__name__) | |
@app.route('/', endpoint='index') | |
def index(): | |
question = request.args.get("q", "").partition(": ")[2] | |
answer = solve(question) | |
print "\nQ: %s?\nA: %s" % (question, answer) |
fun assert_equals (expected, actual, formatter) = | |
if expected = actual | |
then " -- PASS" | |
else "Expected: '" ^ formatter (expected) ^ "' but got '" ^ formatter (actual) ^ "' -- FAIL" | |
fun assert_bool_equals(expected, actual) = | |
if expected = actual then " -- PASS" | |
else "Expected: " ^ Bool.toString (expected) ^ ", but was: " ^ Bool.toString (actual) ^ " -- FAIL" | |
fun assert_true (actual) = assert_bool_equals(true, actual) |