Snippets in category Design Patterns

  • Projecting lists

    Three functions showing how to implement projection for functional lists. First version uses naive recursion and the second one is tail-recursive using the accumulator parameter. The third version extends this with continuation passing.

    43 people like this
    Posted: 1 years ago by Tomas Petricek

  • Memoization and Tail Recursive Function

    Hi, I expressed Memoization and Memoization Tail Recursive on the functions. I hope something useful.

    12 people like this
    Posted: 1 years ago by zecl

  • Tree searching using Tail recursion with continuation

    Sample code which demonstrate tree searching using : Tail recursion with continuation

    9 people like this
    Posted: 1 years ago by Ankur Dhama

  • Abstracting over 'M'

    A higher kind of request to Don Syme... please please please,,,, we desperately need higher kinds!

    13 people like this
    Posted: 1 years ago by Nick Palladinos

  • Monadic Memoization

    Modular memoization within a pure functional setting that is implemented as a convenient computation builder.

    56 people like this
    Posted: 1 years ago by Nick Palladinos

  • Functor => Applicative => Monad

    Yet another attempt of mine to "haskellify" my F# coding.

    8 people like this
    Posted: 1 years ago by Nick Palladinos

  • Undoable Commands

    A simple implementation of an Undoable Command, with a Document to hold a stack of actions. 2 examples of UndoableCommand are given - 1 allows property changes to be remembered, and another which allows the user to execute an action with a corresponding undo. Further examples could include CompositeUndoableCommands where the command is itself a list of commands.

    0 people like this
    Posted: 1 years ago by Neil Danson

  • memoizeBy

    Sometimes you might wish to memoize a function whose input doesn't have the equality and comparison constraints, or maybe the comparison of your given type is just too slow for what you need. To fix this, you simply provide a function which converts the input into something more fitting as an extra parameter.

    7 people like this
    Posted: 10 months ago by Rick Minerich

  • Continuation Monad with Call/CC

    This is an implementation of the Continuation monad using a type, taking an exception handler, and allowing for Call/CC. This specific implementation is mostly Matt Podwysocki's. I have a similar implementation using a purely functional, exception-handler-less version in FSharp.Monad. Until now, I haven't been able to resolve the callCC operator.

    3 people like this
    Posted: 9 months ago by Ryan Riley

  • 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).

    64 people like this
    Posted: 9 months ago by Tao Liu

  • Decorate pattern

    implement the decorate pattern in F#. The decorate pattern is to add new featuures to an object at runtime.

    35 people like this
    Posted: 9 months ago by Tao Liu

  • Observer pattern

    Observer pattern in F#

    33 people like this
    Posted: 9 months ago by Tao Liu

  • Strategy pattern

    Strategy pattern in F#

    59 people like this
    Posted: 9 months ago by Tao Liu

  • State Pattern

    the interest rate is decided by the internal state: account balance

    30 people like this
    Posted: 9 months ago by Tao Liu

  • Adapter pattern

    Invoke the methods from incompatible types

    72 people like this
    Posted: 9 months ago by Tao Liu

  • Command pattern for Redo-Undo

    Command pattern for redo-undo scenario.

    43 people like this
    Posted: 9 months ago by Tao Liu

  • Composite pattern and Visitor Pattern

    use composite pattern to construct a tree and visitor pattern to bring back the traverse result.

    31 people like this
    Posted: 9 months ago by Tao Liu

  • Singleton Pattern

    singleton pattern in F#

    34 people like this
    Posted: 9 months ago by Tao Liu

  • Factory Pattern

    Factory pattern in F#

    57 people like this
    Posted: 9 months ago by Tao Liu

  • Proxy Pattern

    Proxy pattern is a class functioning as an interface to something else.

    37 people like this
    Posted: 9 months ago by Tao Liu

  • Chain of responsibility II

    Unlike the previous chain of responsibility, this version use the pipeline to chain responsibilities.

    79 people like this
    Posted: 8 months ago by Tao Liu

  • Command pattern for Redo-Undo II

    This command redo-undo implement group the command under Do/Undo category.

    58 people like this
    Posted: 8 months ago by Tao Liu

  • Call/CC for Async

    An implementation of call-with-current-continuation for Async.

    2 people like this
    Posted: 8 months ago by Ryan Riley

  • Memoization for dynamic programming

    The snippet shows how to implement reusable memoization function and how to use it to implement efficient Fibonacci number generator using dynamic programming.

    1 people like this
    Posted: 6 months ago by Tomas Petricek

  • Template pattern

    Template pattern is a behavior-based pattern. Realized the importance of high order function, this is a way to use high order function. Still keep the type structure to organize my code.

    34 people like this
    Posted: 6 months ago by Tao Liu

  • Poor Man's DI

    Minimal Dependency Injection (DI) Container in under 60 lines of code implementing the 3 Rs: Register, Resolve, Release. Note: missing thread safety, explicit cycle dependency checking and Fluent interface.

    6 people like this
    Posted: 5 months ago by Phillip Trelford

  • DSL for financial contracts

    Simple domain-specific language (DSL) for describing financial contracts in F#. A contract is represented using a discriminated union. Evaluating a contract gives the orders that may happen at a given date.

    6 people like this
    Posted: 5 months ago by Tomas Petricek

  • Polymorphic Maybe monad with default value.

    Polymorphic (via generics) Maybe monad/computational expression with default value + Zipper

    4 people like this
    Posted: 2 months ago by Daniil

  • Expression parsing with monads

    Compositional expression parsing with monads. https://bitbucket.org/ZachBray/parsad

    4 people like this
    Posted: 1 months ago by Zach Bray

  • JSON parsing with monads

    JSON parsing with monads. See also "Expression parsing with monads" (http://fssnip.net/bi). Author URL: http://www.zbray.com

    5 people like this
    Posted: 1 months ago by Zach Bray