Should We Say That F# Employs Good IO Methods?

Do you mean rerunning on file changes? This is done using the dotnet file watcher. Unfortunately Microsoft declined to make this work with F# script files. So you will have to place your code in an F# console project to use watch. Or use a solution like this to watch FSX files for changes.

This sounds like the β€œauto-run” capability that https://dotnetfiddle.net/ uses that every compiler should have. Syntax editors a important. I’ve only noticed a few live editing capabilities elsewhere such as in the occurrence of the β€œlive HTML.”

Is there a specific reason I can’t take this working function and run its results back into the same function, for example, using separate designations, and results β€œc” as a new target?

ntwilson, taking from your working example. Do you know why this extended function only works by substituting an actual numeric value for the results connected to the initial established function?

open System

let list = [1;2;3]
let target = 2
let mutable Results = String.Empty
list |> List.iteri (fun i obj β†’ if obj = target then
let c = sprintf β€œ%i” (i + 1)
Results ← c )

let d = 2
let list2 = [β€œA”;β€œB”;β€œC”;]
let mutable e = String.Empty
list2 |> List.iteri (fun i obj β†’ if i = d then
let f = sprintf β€œ%d %A” i obj
e ← f )

printf β€œ%s” e

If I’m understanding you correctly, you’re asking why d in your second half has to be a numeric value instead of a string value from the list? That’s because on this line

list2 |> List.iteri (fun i obj β†’ if i = d then

you’re equating i and d, and i is always an int. (The iteri function has type
(int -> 'a -> unit) -> 'a list -> unit, which means the first variable i has to be an int). If you changed that line to

list2 |> List.iteri (fun i obj β†’ if obj = d then

then you could set d to a string, like "C"

let d = "C"
let list2 = ["A"; "B"; "C"]
let mutable e = String.Empty
list2 |> List.iteri (fun i obj -> if obj = d then
  let f = sprintf "%d %A" i obj
  e <- f)
printf "%s" e 

prints 2 "C"

I would like to automate the second results dependent on the first results, however, so is there an a priori for defining d = Results and using (d:int), (Results:int), or something like Int32.TryParse (Results) so that the following function will translate the first functions results into an integer?

Ah, so you want Results from your first block to be the target index for the 2nd block (d)? The int function will do the conversion for you:

open System

let list = [1;2;3]
let target = 2
let mutable Results = String.Empty
list |> List.iteri (fun i obj β†’ if obj = target then
let c = sprintf β€œ%i” (i + 1)
Results ← c )

let d = int Results
let list2 = [β€œA”;β€œB”;β€œC”;]
let mutable e = String.Empty
list2 |> List.iteri (fun i obj β†’ if i = d then
let f = sprintf β€œ%d %A” i obj
e ← f )

printf β€œ%s” e

Or you could just leave Results as an int:

open System

let list = [1;2;3]
let target = 2
let mutable Results = -1
list |> List.iteri (fun i obj β†’ if obj = target then Results ← i + 1 )

let d = Results
let list2 = [β€œA”;β€œB”;β€œC”;]
let mutable e = String.Empty
list2 |> List.iteri (fun i obj β†’ if i = d then
let f = sprintf β€œ%d %A” i obj
e ← f )

printf β€œ%s” e

Totally kick@#$!!! I chose to go with your second solution modified if statement i=d to i=(d-1) for calibrating purposes and excluded %d and i from its sprintf for accuracy. Thanks ntwilson! I’m tabbing your terms as completely solved.

1 Like