what does this error mean, and how to fix it?

greg

Here's my code

let rec Interest a b c =
    if (c=0) then b else Interest(a ((1.0+a)*b) (c-1));;

The error is:

if (c=0) then b else Interest(a ((1.0+a)*b) (c-1));;

-------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

stdin(2,26): error FS0001: Type mismatch. Expecting a 'a but given a 'a -> int -> 'a The resulting type would be infinite when unifying ''a' and ''a -> int -> 'a' >

scrwtp

You've defined Interest as a function that takes three arguments but what you pass doesn't match that. The way it's written, you're only passing in a single argument to the recursive call to Interest - the parenthesized expression a ((1.0=a)*b) (c-1). Here, a is inferred to be a function of two arguments, ((1.0=a)*b) and (c-1).

Long story short, this throws off the type inference algorithm, until it gives up saying that it can't get a hang of what type to give to Interest.

What you want is this:

let rec Interest a b c =
    if (c=0) then b else Interest a ((1.0=a)*b) (c-1)

You'll also have a problem with (1.0=a). This evaluates to a boolean value that you later want to multiply with b. Not sure what the intent is, but you might be looking for something like (if 1.0 = a then 1 else 0)?

Unlike C-like languages that support implicit conversions between "bools" and ints, F# requires you to make all your conversions explicit to ensure correctness (this goes for converting between numeric types as well).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

What does Bus error: 10 mean? And how to fix this error

What does "error: '.class' expected" mean and how do I fix it

What does Grub error "no such device: /.disk/info" mean, and how to fix it?

What does MissingManifestResourceException mean and how to fix it?

What does the error "ACCESS_TAG_MEMORY_OVERRUN_ERROR" in Zebra Android SDK mean, and how to fix it?

"local variable 'e' referenced before assignment" what does this error mean? How do I fix this error?

What does this Vagrant error mean and how do you fix it? For 'public_network' and 'private_network' together

Error: No value given for one or more required parameters. What does this mean? How do I fix?

'No module named 'deploy' : What does this error mean and how do I fix it?

What does this error mean Unsupported class file major version 56 and how do I fix it?

What does the error "list indices must be integers or slices, not str" mean and how can I fix it?

What does this mean and how should I fix this for big files? (malloc_error_break)

In R, what does the error "need at least one panel" mean and how to fix it?

C++ - What does "Incomplete type not allowed" error mean, and how can I fix it?

What does 'index 0 is out of bounds for axis 0 with size 0' mean and how can I fix this error?

In MySQL what does "Overhead" mean, what is bad about it, and how to fix it?

What does Error:(13) Error: The <receiver> element must be a direct child of the <application> element [WrongManifestParent] mean and how do i fix it?

What does the "declare a static final serialVersionUID" warning mean and how to fix?

What does nvprof output: "No kernels were profiled" mean, and how to fix it

What does "Overflow evaluating the requirement" mean and how can I fix it?

What does this mean? How do I fix it? Fatal Exception:main

What does errors like "!=<" mean in agda and how to fix

What exactly does my logcat mean, and how can I fix it?

What does this program mean by Unknown Source and how do I fix it?

What does this error mean?

Android gradle build Error "finished with non-zero exit value 42" , what does it mean and how do i fix it?

What does the rust-analyzer error "could not resolve macro `$crate::format_args`" mean and how do I fix it?

Error 57 - what does it mean?

What does this error message mean?