Search code examples
f#type-constraints

Order of type constraints in F#


This works in F#4.0:

type Something<'a, 'b when 'b :> seq<'b>>() = 

This doesn't:

type Something<'b when 'b :> seq<'b>, 'a>() = 

Unexpected symbol ',' in type name. Expected '>' or other token.

What's the reason that the order of the type constraint matter?


Solution

  • Because it is in the spec - the relevant part is this (from the start of section 5):

    typar-defns:= < typar-defn, ..., typar-defn typar-constraints_opt>
    

    the constraints need to go at the end.

    In this typar-constraints must always start with when and can't appear anywhere else.