I am trying to make a vector library with a hidden Vector type but i get the following error:
Unexpected start of structured construct in definition. Expected '=' or other token
I am trying to learn how modules work, and i took this example from a book where I copied exactly as given and still got this error.
The given errors are :
`error FS0039: The value or constructor 'make' is not defined.
error FS0010: Unexpected start of structured construct in definition. Expected '=' or other token.
`
F# has 2 sintaxis for module
Top level module without the =
module Vector
type Vector = V of float * float
let (~-.) (V(x, y)) = V(-x, -y)
Which acts as a namespace
and module
declaration in one. Components can be indented at the same level as the module Vector
, like in the book example. F# interactive doesn't recognize this form, so you need to use the other form:
Sub modules with the =
:
module Vector =
type Vector = V of float * float
let (~-.) (V(x, y)) = V(-x, -y)
Which require its components to be indented further inside.
Here is the documentation: https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/modules
You need to remove the first type Vector
then just indent the module:
module Vector =
type Vector = V of float*float
let (~-.) (V(x,y)) = V(-x, -y)
let make (x, y) = V(x, y)
let a = make(1.0, 2.0) // V (1.0, 2.0)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.