Git Product home page Git Product logo

fsharpprelude's Introduction

FSharpPrelude

This class library contains a heterogeneous, loosely organized collection of functions and datatypes, the overarching design principles being:

  1. These definitions and utilities could conceivably be used in any F# program.
  2. We attempt to maintain a clear delineation of implementations:
    • purely functional
    • "mostly" functional
    • imperative/object programming. Note Although we do use objects we try to avoid an "object-oriented" approach.
    • Thread-safe vs. unsafe
    • Synchronous vs. async
    • Managed vs. unmanaged. Note For performance reasons many implementations use unmanaged memory access. I am trying to do all of this in F#, awkward as it is. There is a separate Unsafe module that tries to clean this up.
  3. For a given interface, we try to offer multiple implementations using the above

Outline

  • Prelude
  • Graph
  • Collections
  • Math

Some major open design questions I am still thinking about

.NET interfaces vs record-type-of-signatures

In recent years it has become somewhat fashionable for F# programmers to eschew .NET interfaces, as in the following two types:

type IMyInterface =
    abstract member Property : int
    abstract member InstanceMethod : int -> int
    
type MyInterfaceRecord = {
    Property : int
    InstanceMethod : int -> int
}

Semantically these types are basically equivalent, with F#'s object expressions making that equivalency more direct:

let myInterfaceInstance : IMyInterface = {
    new IMyInterface with
        member x.Property = 5
        member x.InstanceMethod = fun x -> x*x
}

let myRecordInterfaceInstance : MyInterfaceRecord = {
    Property = 5;
    InstanceMethod = fun x -> x*x
}

The MyInterfaceRecord is more idiomatically functional and easier to deal with in an ordinary F# program. But the two types are not at all equivalent for the .NET runtime. Specifically, IMyInterface exists as a first-class citizen in IL and can be readily consumed by C# programs, whereas MyInterfaceRecord is an instance of a very complicated class in the F# backend library.

This leads me to suspect that using .NET interfaces is a better choice for performance, and that the syntactic advantages of record interfaces are minimal given that object expressions are largely equivalent. However, at a core level F# is less well-suited for programming with interfaces than C#, with programs often requiring awkward casts and excessive boilerplate code. So there may be disadvantages to using this approach. I will unfortunately need to benchmark this to see what the details actually are :(

fsharpprelude's People

Contributors

nicklecompte avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.