elfs: (Default)
[personal profile] elfs

I can’t remember where I found it, but there was a brilliant explanation of how functional code maps value. Remember, in a functional program, the basic notation is x → y, that is, for every function, it maps value x to another value y. Things like map() map an array to another array, while reduce() maps a single thing (an array) to another single thing (a value). How does functional programming encode other things?


Well, there’s



x → y

x is mapped to y

x → y∪E

x is mapped to y or Error (Maybe)

x → P(y)

x is mapped to all possible values of y (Random Number Generators)

x → (S -> y ⨯ S)

x is mapped to a function that takes a state and returns a value and a new state (State)

x → Σy

x is mapped to the set of all real-world consequences (IO)


The other day I realized that there’s one missing from this list:



x → ♢y

x is mapped to y eventually (Promises)


I’m not sure what to do with this knowledge, but it’s fun to realize I actually knew one more thing than my teacher.  Note that the first case, x → y, really does cover all sum (union) and product (struct) types, which tells me that the ML-style languages’ internal type discrimination features are orthogonal to their encapsulation of non-linear mappings.


The really weird thing is to realize that the last four are all order-dependent.  They’re all about making sure things happen in the correct sorted order (and temporal order, if that matters).  That leads me to think more about compiler design…

http://pendorwright.com/

Date: 2016-08-31 09:29 pm (UTC)
From: (Anonymous)
Elf,
I hope it's okay to call you Elf. I wasn';t sure how to get a message to you. Comments on the pendorwright.com don't appear to be working. In fact, I am generating an error from the main page when I click on the Masks or Lost in the Woods links from that page. The comments, entries & new stories links just seems to be dead.
Okay - just a final "Hey, big fan!" and I'll let you be. Peace!

-GWN

Profile

elfs: (Default)
Elf Sternberg

December 2025

S M T W T F S
 12345 6
78910111213
14151617181920
21222324252627
28293031   

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Jan. 3rd, 2026 01:06 pm
Powered by Dreamwidth Studios