Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is "monadic reflection"?

Tags:

f#

What is "monadic reflection"?

How can I use it in F#-program?

Is the meaning of term "reflection" there same as .NET-reflection?

like image 691
Tuomas Hietanen Avatar asked Feb 22 '10 13:02

Tuomas Hietanen


People also ask

What is a monadic value?

In short, a monad is a way to structure computations in terms of values and sequences of computations using typed values. But since sequencing is often done by feeding one function into the next, you get some type discipline and computational leverage over what kinds of operations can follow previous operations.

What is a monadic type?

So in simple words, a monad is a rule to pass from any type X to another type T(X) , and a rule to pass from two functions f:X->T(Y) and g:Y->T(Z) (that you would like to compose but can't) to a new function h:X->T(Z) .


2 Answers

Monadic reflection is essentially a grammar for describing layered monads or monad layering. In Haskell describing also means constructing monads. This is a higher level system so the code looks like functional but the result is monad composition - meaning that without actual monads (which are non-functional) there's nothing real / runnable at the end of the day. Filinski did it originally to try to bring a kind of monad emulation to Scheme but much more to explore theoretical aspects of monads.

Correction from the comment - F# has a Monad equivalent named "Computation Expressions"

Filinski's paper at POPL 2010 - no code but a lot of theory, and of course his original paper from 1994 - Representing Monads. Plus one that has some code: Monad Transformers and Modular Interpreters (1995)

Oh and for people who like code - Filinski's code is on-line. I'll list just one - go one step up and see another 7 and readme. Also just a bit of F# code which claims to be inspired by Filinski

like image 182
ZXX Avatar answered Jan 06 '23 12:01

ZXX


I read through the first Google hit, some slides:

http://www.cs.ioc.ee/mpc-amast06/msfp/filinski-slides.pdf

From this, it looks like

  1. This is not the same as .NET reflection. The name seems to refer to turning data into code (and vice-versa, with reification).
  2. The code uses standard pure-functional operations, so implementation should be easy in F#. (once you understand it)
  3. I have no idea if this would be useful for implementing an immutable cache for a recursive function. It look like you can define mutable operations and convert them to equivalent immutable operations automatically? I don't really understand the slides.

Oleg Kiselyov also has an article, but I didn't even try to read it. There's also a paper from Jonathan Sobel (et al). Hit number 5 is this question, so I stopped looking after that.

like image 24
Nathan Shively-Sanders Avatar answered Jan 06 '23 12:01

Nathan Shively-Sanders