Skip to content

Instantly share code, notes, and snippets.

@vivainio
Last active May 11, 2016 21:36
Show Gist options
  • Select an option

  • Save vivainio/9b298667f9f2c05e73f4023df250e1ec to your computer and use it in GitHub Desktop.

Select an option

Save vivainio/9b298667f9f2c05e73f4023df250e1ec to your computer and use it in GitHub Desktop.

FSharp intro

Why

Less code, little to no C# like source bloat because of:

  • Type inference
  • Automatic generics
  • Functions instead of methods
  • seqs and tuples + unpacking (a'la python)
  • pattern matching ("switch case" that matches types & unpacks)
  • modern, tasteful syntax (esp. vs C# / Java / JS): Indentation based blocks, no semicolons, less (braces)
  • |> operator (no need for "extension methods", code reads left to right)

Demo 1:

  • Connect to mssql db with type provider
  • Get groups
  • Get users + associated groups
  • Display stuff + refactor

Demo 2:

  • Show records + type inference
  • Show automatic generics
  • show seq {} + pattern matching
Copy link

ghost commented May 11, 2016

Some additional ideas:

  • Option Type: No Null
  • Units of Measure: Type-safety for numbers
  • Type Providers: Automatic generation of types for things like JSON
  • Async: like C# async/await probably a mention that async {..} and seq {...} are things you could build yourself (Computation Expression)

The mention of the Option type could be part of the "Why". by the way, some other small "why" reason why i like F#: Currying, Partial Application, Unit type (no void), everything is an expression.

Type-safety could be a small demo on it's own. Like some calculation with money, weights and so on.

Async + Type providers could be a demo that downloads a JSON/CSV file from a website and do some basic calculation with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment