Reputation: 3061
let fibgen (x,y) = if(x < 4000000) then Some(x+y, (y, x+y)) else None
let fibseq = Seq.unfold fibgen (1,1)
Type Mismatch error on Second line. what am I doing wrong? I am using F# 2.0
First Done Reset Session on My interactive Window still same error
and then Restarted My Project now Working fine.yes i had below piece of code execued in same session
// The option type is a discriminated union.
type Option<'a> =
| Some of 'a
| None
Interactive window Output as below
val fibgen : int * int -> Option<int * (int * int)>
>
Eluer2.fs(27,25): error FS0001: Type mismatch. Expecting a
int * int -> ('a * (int * int)) option
but given a
int * int -> Option<int * (int * int)>
The type '('a * (int * int)) option' does not match the type 'Option<int * (int * int)>'
>
Upvotes: 1
Views: 211
Reputation: 243051
As pointed by Carsten in a comment, the code works fine if you enter it in clean F# Interactive. Since the compiler complains that Option<'T>
does not match 'T option
, I would guess that you accidentally wrote some code that re-defined Some
and None
before using the unfold
function. Perhaps you wrote something like this (and evaluated that in F# Interactive):
type Option<'T> =
| None
| Some of 'T
This hides the standard definitions of Some
and None
that are constructors of the 'T option
type defined in the standard F# library (and that are expected by the unfold
function).
You can reset the F# Interactive session by right-clicking in the window and choosing "Reset Session". This removes previous declarations and the code should work fine.
Upvotes: 5