Skip to content

Instantly share code, notes, and snippets.

@dsyme
Created February 5, 2016 12:09
Show Gist options
  • Save dsyme/a02b19b9e55ab392a06d to your computer and use it in GitHub Desktop.
Save dsyme/a02b19b9e55ab392a06d to your computer and use it in GitHub Desktop.
type Animal() = class end
type Dog() = inherit Animal()
let feed (animals: seq<Animal>) = ()
feed [ Dog(); Animal() ]
@Tarmil
Copy link

Tarmil commented Feb 23, 2016

This works indeed, but unfortunately it prevents other use cases which would be allowed by using seq<#Animal>:

type Animal(name: string) = class end

type Dog(name: string) = inherit Animal(name)

let feed (animals: seq<Animal>) = ()

let myDogs = List.map Dog ["Lassie"; "Rex"]
feed myDogs
// the type 'Dog list' is not compatible with the type 'seq<Animal>'

unless we open the can of worms of co/contravariant type parameters :-)

@robkuz
Copy link

robkuz commented Jul 26, 2016

But

let myDogs:seq<Animal> = [ Dog(); Animal() ]

doesn't compile and I find that highly irritating

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