Hello world will not compile with "No value or constructor defined"

let prefix prefixString baseString = 
    prefixString + " " + baseString

prefix "Hello" "World"

      

With the code above, I am getting the error Stuff.fs(34,1): error FS0039: The value or constructor 'prefix' is not defined.

I don't quite understand why this is happening since I look

+3


source to share


1 answer


In the comment, you mentioned that you are using a snippet using the "make selection" command. This command runs a code snippet in F # Interactive that is initially undefined. So, if you select and run only the last line, you get:

> prefix "Hello" "World";;
stdin(1,1): error FS0039: The value or constructor 'prefix' is not defined

      

This is because F # Interactive doesn't know what the definition prefix

is - it doesn't automatically look for it in your file. You can fix this by selecting everything and running all the code in one interaction, or you can run the definition first and then the last line, that is:



> let prefix prefixString baseString = 
    prefixString + " " + baseString;;
val prefix : prefixString:string -> baseString:string -> string

> prefix "Hello" "World";;
val it : string = "Hello World"

      

Note that when you run the first command, F # Interactive will print the type of the defined functions so you can see what has just been defined.

The fact that F # Interactive has its own "state of the world" is very important, as it also means that you need to rerun functions after changing them so that subsequent commands use the new definition.

+7


source







All Articles