[personal profile] neelk
I think I've written the most polymorphic non-toy two-line ML program ever.
val cross : (('a -> 'b -> 'c) -> 'd -> 'e -> 'f) ->
            (('g -> 'h -> 'i) -> 'j -> 'b -> 'c) ->
            ('a -> 'g -> 'h -> 'i) -> 
            'e -> 'd -> 'j -> 'f

Here's the definition:

let cross outer inner f init xs ys =
  outer (fun x acc -> inner (fun y acc -> f x y acc) ys acc) xs init



It encapsulates a nested iteration over two arbitrary collections. The first two arguments are folds over two different datatypes, the third and forth arguments are the step function and initial argument, and the last two are the two collections. I am tempted to try and generalize this so it's a combinator that lets you iterate over an arbitrary number of collections, but that seems over the top -- I've already got 10 polymorphic arguments!

Date: 2006-10-20 03:26 am (UTC)
From: [identity profile] jeffwik.livejournal.com
I choose to believe this is some sort of profanity, or obscenity, or both.

Date: 2006-10-20 04:29 am (UTC)
From: [identity profile] simrob.livejournal.com
If, by profanity, you mean profanely awesome.

I would have voted you "most likely to write the most polymorphic ML function ever" of everyone I know even before this happened, really. It's just the right brand of mind-bending awesome.

Profile

neelk

March 2007

S M T W T F S
    123
4567 8910
11121314151617
18192021222324
252627 28293031

Style Credit

Expand Cut Tags

No cut tags
Page generated May. 22nd, 2025 06:44 pm
Powered by Dreamwidth Studios