SERVING THE QUANTITATIVE FINANCE COMMUNITY

Polter
Posts: 2526
Joined: April 29th, 2008, 4:55 pm

### F# / F Sharp

VivienB: I don't think there's anything necessarily inherently "uni-paradigm" about monads.Just think of them (or, in particular, of monadic binding with the bind operation >>= ) as a simple tool for, e.g., composing stuff, while maintaining separation of concerns: http://www.haskell.org/haskellwiki/MonadFor instance, here's how they can help in composing async ops (in an actor model framework) in C++:[PDF] http://github.com/boostcon/cppnow_prese ... raw=true// see slide 16/17, entitled "The Lack of Monads in C++" -- where the title explains the use of a library-based solution, since this feature is not in the core language; one could say that this could be even taken as an illustration of the point (which you seem to agree with) that tools associated with one paradigm can really shine when combined with others in a multiparadigm approach.
Last edited by Polter on May 26th, 2013, 10:00 pm, edited 1 time in total.

VivienB
Posts: 130
Joined: August 6th, 2012, 3:32 pm

### F# / F Sharp

Polter
Posts: 2526
Joined: April 29th, 2008, 4:55 pm

### F# / F Sharp

Interestingly, monadic IO is what makes Haskell impure: http://conal.net/blog/posts/the-c-langu ... ionalConal (the author of this post) seems to suggest this makes IO "an imperative crutch."Personally, I'm wondering whether, as opposed to being a problem, it's not a sign of pragmatism
Last edited by Polter on May 26th, 2013, 10:00 pm, edited 1 time in total.

Cuchulainn
Posts: 62608
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### F# / F Sharp

Last edited by Cuchulainn on May 26th, 2013, 10:00 pm, edited 1 time in total.
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl

Cuchulainn
Posts: 62608
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### F# / F Sharp

What do you think of F# Math (II.) - Using matrices for graph algorithms.InnovativeOK,Can do the same in C# etc.Solution look for problemAdded value in FP , not data structure???
Last edited by Cuchulainn on May 26th, 2013, 10:00 pm, edited 1 time in total.
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl

VivienB
Posts: 130
Joined: August 6th, 2012, 3:32 pm

### F# / F Sharp

QuoteOriginally posted by: CuchulainnI think a two-layer model is good:1. Data (OOP + structs)2. Function (FP aproach + all that fold stuff) operating (read and write) on the data in level 1. You can use OOP for this layer using subtype polymorphism but explosion in the number of classes...I agree with this model (assuming that some function, eg functions on matrix, are available an can be used functionally inside the FP part).QuoteOriginally posted by: CuchulainnTuples are also very useful; how did we live without them in C++ for the last 25 years?ADT are also very useful (not especially in this case), but are not in C++ (correct me if I'm wrong).

Cuchulainn
Posts: 62608
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### F# / F Sharp

QuoteOriginally posted by: VivienBQuoteOriginally posted by: CuchulainnI think a two-layer model is good:1. Data (OOP + structs)2. Function (FP aproach + all that fold stuff) operating (read and write) on the data in level 1. You can use OOP for this layer using subtype polymorphism but explosion in the number of classes...I agree with this model (assuming that some function, eg functions on matrix, are available an can be used functionally inside the FP part).QuoteOriginally posted by: CuchulainnTuples are also very useful; how did we live without them in C++ for the last 25 years?ADT are also very useful (not especially in this case), but are not in C++ (correct me if I'm wrong).So, I think we agree on a ADT + FP model? ADTs are just types, yes? In this would be a class(?)In C++ 11 there is std::tuple (not quite an ADT) and also boost::tupleNiklaus Wirth was rightData Structures + Algorithms = Programs
Last edited by Cuchulainn on May 27th, 2013, 10:00 pm, edited 1 time in total.
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl

VivienB
Posts: 130
Joined: August 6th, 2012, 3:32 pm

### F# / F Sharp

QuoteOriginally posted by: CuchulainnQuoteOriginally posted by: VivienBQuoteOriginally posted by: CuchulainnI think a two-layer model is good:1. Data (OOP + structs)2. Function (FP aproach + all that fold stuff) operating (read and write) on the data in level 1. You can use OOP for this layer using subtype polymorphism but explosion in the number of classes...I agree with this model (assuming that some function, eg functions on matrix, are available an can be used functionally inside the FP part).QuoteOriginally posted by: CuchulainnTuples are also very useful; how did we live without them in C++ for the last 25 years?ADT are also very useful (not especially in this case), but are not in C++ (correct me if I'm wrong).So, I think we agree on a ADT + FP model? ADTs are just types, yes? In this would be a class(?)In C++ 11 there is std::tuple (not quite an ADT) and also boost::tupleNiklaus Wirth was rightData Structures + Algorithms = ProgramsADTs (I used this acronym for Algebraic Data Type, not for Abstract Data Type) are types that represent disjoint unions. It can be used to represent complex data structures instead of using classes. Here is a blog post that explain how to built ADTs in C++ using boost.In our case, it can represent the model parameters type for instance: $M=\oplus_i (\{model_i\} \times M_i$) where $M_i$ is the set of parameters for the model $model_i$.

Cuchulainn
Posts: 62608
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### F# / F Sharp

Here's the kind of approach that I was alluding to; it is super-flexible. ADT Lattice is the level 1 object.
Last edited by Cuchulainn on May 27th, 2013, 10:00 pm, edited 1 time in total.
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl

VivienB
Posts: 130
Joined: August 6th, 2012, 3:32 pm

### F# / F Sharp

I'm sorry, I didn't use C++ for a long time, so your code is not clear for me

chocolatemoney
Topic Author
Posts: 322
Joined: October 8th, 2008, 6:50 am

### F# / F Sharp

Yes, we all agree on a mixed model, benefiting from the best of both worlds.Happy to read that my initial guess, back on Friday, has been confirmed.@Vivien:"I don't see where you need states. I think PDE can be implemented in a pure functional style without using monad (or imperative prog)."State, in my mind, is for example applying the scheme on the lattice from t=now to T=expiry, following the application of the ICs and eventually doing something else at expiry.I guess you refer to "lack of mutability" - I call it "state".I thought a monad could take care of the work pipeline.*PURE* Functional programming (scala) is something very new to me - I have been working with Scala for something like 1-2 years.I'd be happy to see your pure functional implementation of a PDE solver, if you could share...PS: Is F# the language of choice at LexiFi?
Last edited by chocolatemoney on May 27th, 2013, 10:00 pm, edited 1 time in total.

chocolatemoney
Topic Author
Posts: 322
Joined: October 8th, 2008, 6:50 am

### F# / F Sharp

template <typename S, typename T, class Node> Node BackwardInduction(Lattice<S,T,Node, typeBin>& lattice, const std::function<Node (const Node& upper,const Node& lower)>& generator, const std::function<Node (const Node& node)>& endCondition) Shuld BackwardInduction return a void? Does it apply the scheme directly on the lattice, isn't it?

chocolatemoney
Topic Author
Posts: 322
Joined: October 8th, 2008, 6:50 am

### F# / F Sharp

Pestering the thread again.Hey, I am not sure I am going in the right direction, but here is a state monad in scala.The idea is that the monad could pass along the lattice, instead of the fibonacci serie, and do all that has to be done.Bad idea?

Cuchulainn
Posts: 62608
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### F# / F Sharp

QuoteOriginally posted by: chocolatemoneytemplate <typename S, typename T, class Node> Node BackwardInduction(Lattice<S,T,Node, typeBin>& lattice, const std::function<Node (const Node& upper,const Node& lower)>& generator, const std::function<Node (const Node& node)>& endCondition) Shuld BackwardInduction return a void? Does it apply the scheme directly on the lattice, isn't it?It return a value (e.g. price at t =0 or the value in the lattice interpolation method, e.g. Neville). But maybe a void is better and then just let the client ask for the value at the tip of the lattice.
Last edited by Cuchulainn on May 27th, 2013, 10:00 pm, edited 1 time in total.
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl

Cuchulainn
Posts: 62608
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### F# / F Sharp

QuoteOriginally posted by: VivienBI'm sorry, I didn't use C++ for a long time, so your code is not clear for me Ok C++ templates are awful cryptic I agree. Here is the V1 code and it feels like choco's state monad moving up the lattice?I am sure it is possible without [] but later.I see 'generator' as a lambda as in the style of STL or C# delegates.hth
Last edited by Cuchulainn on May 27th, 2013, 10:00 pm, edited 1 time in total.
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl