0

I have noticed this a few times now. An example of an offending function is Array.take. In a script file I can write

[|1; 2; 4; 7; 6; 5|]
|> Array.take 3
|> Array.iter (printfn "%d")

and this works without a problem. But if I try to use Array.take in an actual source file, I get the following error

[|1; 2; 4; 7; 6; 5|]
|> Array.take 3 // RED SQUIGGLY ERROR HERE
|> Array.iter (printfn "%d")

and the error message is:

The value, constructor, namespace or type 'take' is not defined

So, what gives? Thanks in advance for your help.

1 Answer 1

4

I suspect that you're seeing this is due to different versions of F#. There was an attempt to regularise a lot of the List Seq and Array functions in F# 4.0, see: https://visualfsharp.codeplex.com/wikipage?title=Status

One of the functions that was added as part of that process was Array.take.

In F# interactive, no doubt you are using the latest version of F# but presumably you are not in your compiled project.

This could be because you haven't changed the version in the project settings or it could be because you have a nuget package attached your project which references a specific version of F# Core via nuget.

If you go to your project properties, you should see an a 'Target F# Runtime' setting, change this to F# 4.0. If I remember correctly, a nuget reference to a specific F# Core version will prevent you from changing that setting, in which case you'll need to delete the reference to F# core and re-add the correct version as a reference from the list of assemblies.

Sign up to request clarification or add additional context in comments.

2 Comments

the Target F# Runtime is set to 4.3.0.0 and is greyed out. The project is using version 4.3.0.0 of FSharp.Core. In spite of that, I encounter the problem.
@Shredderroy F# Core 4.3.0.0 corresponds to F# 3.0. F# 4.0 uses F# Core version 4.4.0.0. Delete the reference to F# Core and re-add it from the list of Extensions assemblies.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.