f#-interactive

Make a List from a Tuple List on F#

◇◆丶佛笑我妖孽 提交于 2019-12-11 02:40:06
问题 Lets say I have a tuple list. Just to make it easier to refer to, its a coordinates with an x and y values. let test = [(1,34);(2,43);(3,21);(1,51);(2,98);(3,56);(1,51)] I want to make another list using test so that if I only want value which has an x value of 1, it would return [34;51;51] 回答1: You need to filter the list first to get tuples that have an x value of 1, then map the results to get the y value : [(1,34);(2,43);(3,21);(1,51);(2,98);(3,56);(1,51)] |> List.filter (fun (x,_)->x=1)

F#:Block following this 'let' is unfinished. Expect an expression

丶灬走出姿态 提交于 2019-12-11 00:30:19
问题 I know in F# we should bind every single value to a name. And I think mine is ok??? But in the if statement I have the following error. Block following this 'let' is unfinished. Expect an expression and it comes from let min= List.nth list i . As far as I know I bounded the min to List.nth list i . So why it should be an error? let mutable list =[-1;2;3;4] let mutable min=list.[0] let mutable i=1 if min<=0 then let min= List.nth list i 回答1: If you want to mutate a mutable variable, you can

Map on Map<'a, int>

别来无恙 提交于 2019-12-10 21:24:48
问题 I have the following type : type MultiSet<'a when 'a: comparison> = MSet of Map<'a, int> and I now want to declare af map function for this type with the signature : ('a -> 'b) -> Multiset<'a> -> Multiset<'b> when 'a : comparison and 'b : comparison I have tried : let map m ms = match ms with | MSet s -> MSet ( Map.map (fun key value -> m key) s ) But that it has the signature : ('a -> int) -> Multiset<'a> -> Multiset<'a> when 'a : comparison What is wrong with my implementation when I want

in F# on MAC OSX and Ubuntu I get an error running FSI in 4.0

寵の児 提交于 2019-12-10 10:19:59
问题 I need System.Numerics in F# EDIT I think the question is can fsi run with the 4.0 runtime and if so how do I configure it I run "mono /bin/Fsi" in the Fsharp 4.0 dir I get the following error in both OSX 10.6.4 and Ubuntu 10.1. I am sure I am missing a path or something Please note the paths are different on the MAC but I got the same error error FS0078: Unable to find the file 'System.Numerics.dll' in any of /opt/mono-2.8/lib/mono/2.0 /home/gary/Downloads/FSharp-2.0.0.0/v4.0/bin /home/gary

How to get F# scripts files and other script languages to work like .exe, .cmd, and .bat files in Windows

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-09 23:39:32
问题 It is possible to configure F# script files so that they may be invoked directly without directly specifying the script runner application and their file extension, and made accessible through the command PATH environment variable. The steps to do so are as follows: Set the particular script engine as the default "open with" program for the script file type extension using Windows Explorer Appended the script extension to the PathExt environment variable, which will classify it as executable

Defining Modules VS.NET vs F# Interactive

Deadly 提交于 2019-12-08 15:59:23
问题 I have written this code which compiles and works perfectly in VS.NET 2010 module ConfigHandler open System open System.Xml open System.Configuration let GetConnectionString (key : string) = ConfigurationManager.ConnectionStrings.Item(key).ConnectionString however when I do a control + A and Alt + Enter to send this to FSI I get an error ConfigHandler.fs(2,1): error FS0010: Unexpected start of structured construct in definition. Expected '=' or other token. OK. So I change my code to module

How do I use breakpoints in F# interactive?

≯℡__Kan透↙ 提交于 2019-12-08 14:39:57
问题 I've started researching some ideas in algorithms using VS2010 and F# interactive. So, I've created a DebugScript.fsx , I write some code there and eventually send it to F#Int to test it. At some some moment I need to catch a bug. But I can't place a breakpoint even in a simple for loop: for i in stringarray do printfn "%s" i When I press F9 to set a breakpoint, the VS show a red circle with a warning sign. The hint for it is "The breakpoint will not currently be hit". Surely, I did open

F# Why can't I use the :? operator in F# interactive?

泪湿孤枕 提交于 2019-12-08 05:55:19
问题 I am trying to check if a variable is of a certain type like so: let s = "abc" let isString = s :? string but in F# interactive, I get the following error: error FS0016: The type 'string' does not have any proper subtypes and cannot be used as the source of a type test or runtime coercion. Why is this happening? I expect isString to be a bool. 回答1: Because you are trying with a sealed type. Try instead this: let s = box "abc" let isString = s :? string There is no point in doing this coercion

F# Why can't I use the :? operator in F# interactive?

南楼画角 提交于 2019-12-08 05:29:31
I am trying to check if a variable is of a certain type like so: let s = "abc" let isString = s :? string but in F# interactive, I get the following error: error FS0016: The type 'string' does not have any proper subtypes and cannot be used as the source of a type test or runtime coercion. Why is this happening? I expect isString to be a bool. Because you are trying with a sealed type. Try instead this: let s = box "abc" let isString = s :? string There is no point in doing this coercion tests with sealed types since they can't have any subtype and that's what the error message is telling you.

Why does F# Interactive behave differently than compiler with regards to immutable value definition?

こ雲淡風輕ζ 提交于 2019-12-07 04:22:58
问题 In reading John Palmer's answer to What is the difference between mutable values and immutable value redefinition?, John notes that This sort of redefinition will only work in fsi. In working with F# Interactive (fsi) I guess I subconsciously knew it, but never paid attention to it. Now that it is apparent, why the difference? More specifically please explain how the internals are different between fsi and the compiler such that this occurs by design or result of differences? If the answer