Skip to content

Instantly share code, notes, and snippets.

@JaggerJo
Created September 17, 2020 21:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JaggerJo/509c83da994f7bf975f2a8eb6bdc3336 to your computer and use it in GitHub Desktop.
Save JaggerJo/509c83da994f7bf975f2a8eb6bdc3336 to your computer and use it in GitHub Desktop.

Fsharp goodies (Vol 1)

After the 'F# Compiler Community Session' I read the first 1K lines of SyntaxTree.fs. That's what I learned about the language.

  1. There is a byte string

    let a = "abc"B
    val a : byte [] = [|97uy; 98uy; 99uy|]
  2. You can specify the expected type behind any expression

    let add a b = (a + b) : int 
    val add : a:int -> b:int -> int
  3. Discriminated Union augmentations can be disabled

    [<DefaultAugmentation(false)>]
    type Animal =
        | Snake
        | Dog
        | Cat
    
    	(* fails when default augmentations are enabled (default) *)
        member this.IsDog =
            match this with
            | Dog -> true
            | _ -> false
  4. There is a strange but supported property setting syntax (but please don't use it)

    let arr = ResizeArray([|1; 2; 3|])
    arr.Item(0) <- 42
@dsyme
Copy link

dsyme commented Sep 18, 2020

Yes please don't use 3 or 4

3 has bugs in conjunction with other features

4 is actually a dotnet and vb thing

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