News for hackers. Stuff that matters.
Re:Fantastic DSLs and where to find them by Veedrac on Thursday June 29, 2017 @12:53PM (#14664775)
The type of the reduction function would just be something like

    (X, Y) -> (X Y)
     args     pair
The type of a reduce that has an initial seed is something like

     X   -> ((E, X) -> X) -> [E]  ->   X
    seed       reducer       list    result
The result is going to need to be some recursively defined type, which I'll call List,

    type List E = E | (E (List E))
Apply these together trivially

    (List E) -> ((E, (List E)) -> (List E))
             -> [E]
             -> (List E)
Re:Fantastic DSLs and where to find them by BoiledCabbage on Thursday June 29, 2017 @03:26PM (#14666152)
And this is the other thing I like about the haskell/ML collection of languages. The description you gave above is extremely concise and direct. If you're familiar with the language being used it's a very efficient form of communication.

I've noticed that working in languages of that family gives you a vocabulary to talk about things that previously would have been very wordy to discuss.

Languages with these types of type features provide easy abstractions to illuminate structure and patterns begin discussing new ideas that previously would've been considered on off code.

Re:Fantastic DSLs and where to find them by Veedrac on Thursday June 29, 2017 @03:40PM (#14666241)
FWIW, this can be inferred fully automatically. Type

    let pair = fun x -> fun y -> { _0 = x; _1 = y }

    let rec reduce = fun init -> fun combine -> fun xs ->
        match xs with
            [] -> init
          | x :: rest -> reduce (combine x init) combine rest

    let test = reduce 0 pair [1; 2; 3; 4]
into https://www.cl.cam.ac.uk/~sd601/mlsub/ to see a demonstration.