Recent snippets

  • Counting Evens and Odds via Z3

    Counting Evens and Odds via Z3.

    0 people like this

    Posted: 3 days ago by NIck Palladinos

  • Universal Mutator

    Defines a generic `mutate : 'T -> 'T` function that structurally mutates every value in the object graph, without performing new allocations. Needless to say, this is intended for educational purposes only.

    2 people like this

    Posted: 3 days ago by Eirik Tsarpalis

  • F# SRTP of Type Classes from OO Perspective

    Similar to http://fssnip.net/7Tr, this implementation translates the Scala from https://functional.works-hub.com/blog/Type-classes-from-OO-perspective but uses statically resolved type parameters to show how something similar could be done with computation expression instances. It's really too bad you have to pass an instance of the implementation. It would be nice to be able to specify a module or class with a static member.

    1 people like this

    Posted: 8 days ago by Ryan Riley

  • F# version of Type Classes from OO Perspective

    This is the F# translation of the Scala program written for https://functional.works-hub.com/blog/Type-classes-from-OO-perspective. F# doesn't have implicits, so type classes don't work. However, it's interesting to see just how close you can come by passing an instance of the implementation. By flipping the parameters, you can use partial application to create type-specific functions. Here, we follow the use of the interface, but we could also use statically resolved type parameters to structurally infer different implementations.

    1 people like this

    Posted: 8 days ago by Ryan Riley

  • Staged Trampoline

    Staged Trampoline.

    1 people like this

    Posted: 10 days ago by NIck Palladinos

  • yin-yang puzzle in F#

    yin-yang puzzle, based on https://groups.google.com/forum/#!msg/comp.lang.scheme/Fysq_Wplxsw/awxEZ_uxW20J

    0 people like this

    Posted: 11 days ago by NIck Palladinos

Popular snippets

  • Creating objects with events

    This snippet shows how to create objects with events in F#. It shows both simple event (to be used from F#) and a .NET compatible event with specific delegate type.

    76 people like this

    Posted: 6 years ago by Tomas Petricek

  • Factory Pattern

    Factory pattern in F#

    69 people like this

    Posted: 6 years ago by Tao Liu

  • FSX Structure

    I use this basic template when writing .fsx files that I might want to compile. It adjusts the difference in command line/entrypoint handling between a script and a compiled assembly. This example shows the details for a WPF script — replace the #r's and/or remove the STAThread for a WinForms or Console script.

    115 people like this

    Posted: 6 years ago by Blake Coverett

  • Chain of responsibility

    The following sample wants to make sure the person’s age is between 18 and 65, weight is no more than 200 and tall enough (>120).

    75 people like this

    Posted: 6 years ago by Tao Liu

  • Composing a list of functions

    Composition of functions in F# is easily achieved by using the >> operator. You can also chain an arbitary amount of functions (represented as a list or sequence) together by folding the list/seq with >>. [More formally: the set of endomorphisms 'a -> 'a forms a monoid with the binary, associative operator ">>" (or "<<") and the neutral element "id".]

    77 people like this

    Posted: 6 years ago by Novox

  • Top-Down-Operator-Precedence Parser

    F# implementation of a generic Top-Down-Operator-Precedence Parser as described in this paper http://portal.acm.org/citation.cfm?id=512931 Example starts at line ~300

    86 people like this

    Posted: 6 years ago by fholm

Snippets by tags

design patterns (18) http (14) game (30) computation builder (14) web (23) wpf (18) algorithms (25) pattern matching (12) array (18) seq (48) lazy (18) monad (20) fold (19) math (32) json (12) sequences (47) kata (17) fparsec (14) reflection (18) sequence (29)

View all...

Database contains 2132 snippets out of which 1471 is public.