Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pure functional using F#

Is it possible to force F# to behave like a pure functional language like Haskell? Maybe using some compiler directives?

PS: since I come from a C/C++ background, I want to force myself to learn functional programming without learning Haskell :)

like image 514
r00kie Avatar asked Oct 06 '10 04:10

r00kie


1 Answers

You can't force this behavior in F#, but as Brian said discipline is your best friend. E.g. don't use mutable, for or while loops, ref keywords, etc. Also stick with purely immutable data structures (discriminated union, list, tuple, map, etc). If you need to do IO at some point, architect your program so that they are separated from your purely functional code.

Don't forget functional programming is all about limiting and isolating side-effects.

like image 123
Stringer Avatar answered Dec 18 '22 12:12

Stringer