In recent versions of F# (FSharp.Core 4.3.1.0) the following all compile:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
let g y = ()
let rec f x =
    match x with
    | [] -> g 1
    | _::_ -> g true

let rec g' y = ()
    and f' x =
        match x with
        | [] -> g 1
        | _::_ -> g true

let rec f'' x =
        match x with
        | [] -> g 1
        | _::_ -> g true
    and g'' y = ()

g, g' and g'' are all 'a -> unit.

By on 12/11/2016 7:14 PM ()

Hi there,

You must currently fully type annotate the function or method being used at multiple type instantiations within the recursive block, e.g.

1
2
3
4
5
6
7
8
9
10
11
12
 

#light

let rec f x =
  match x with
  | []   -> g 1
  | _::_ -> g true

and g<'a> (y:'a) : unit = ()

Note you must include all of

  • the type paramater declarations
  • any type parameter constraints
  • the argument types
  • the return type

This can be a bit annoying when your code involved #types, whose full type annotation is somewhat longer. We're looking at some additions in this area to ease this.

Thanks

Don

By on 7/11/2008 6:40 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us
Built with WebSharper