FS0003: This value is not a function and cannot be applied

FS0003: This value is not a function and cannot be applied

I am trying to practise type option in F# on interactive. but I am having the problem below..

let r = Some (4);;

Program.fs(278,9): error FS0003: This value is not a function and cannot be applied
>

let readValue (opt: 'a option) = 
  match opt with
  |Some (v) -> v
  |None -> failwith "no value";;

Program.fs(283,4): error FS0019: This constructor is applied to 1 argument(s) but expects 0

Don't use tuple syntax

let r = Some 4;;

 let readValue a =
     match a with
     |Some v -> v
     |None -> failwith "error";;

Both of the above work as shown here

Line numbers in your diagnostic messages (Program.fs(278,9) and Program.fs(283,4)) allow to assume that you've taken these fragments from some code. As F# extensively uses type inference your snippets are having problems because of something contained above line 278 in the original source code file Program.fs.

Below I ran a fresh instance of FSI and executed given code fragments alone; they do not have any problem per se:

C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC>fsi

Microsoft (R) F# Interactive version 11.0.60315.1
Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;

> let r = Some (4);;

val r : int option = Some 4

> let readValue (opt: 'a option) =
-    match opt with
-    |Some (v) -> v
-    |None -> failwith "no value";;

val readValue : opt:'a option -> 'a

  • Back aarticle:
  • Next aarticle: No
  • Copyright © 2007-2012 www.chuibin.com Chuibin Copyright