54 questions
0
votes
1
answer
215
views
Running F# script in Windows seamlessly as powershell script
In Windows, given a PowerShell script script1.ps1 and a command or PowerShell prompt, starting the script is just a matter of writing its name an enter in the keyboard:
> .\script1.ps1 <...
2
votes
2
answers
113
views
Is it possible to use ASP.NET Core within an F# fsx script?
Found that the question was pondered a few years ago: https://github.com/dotnet/fsharp/issues/8688
My code looks like
#r "nuget: Microsoft.NETCore.App"
#r "nuget: Microsoft.NETCore.App....
2
votes
1
answer
124
views
FileHelpers not using correct Date format
I am attempting to parse records with a DateTime field, but FileHelpers is not using the format I am providing. The following is an F# script that should parse the records but throws an error. I ...
3
votes
1
answer
224
views
F# Literate pass arguments to script file
I am using F# Formatting to do some Literate programming.
My use case is that I have a couple of hundred data sets that I need to run through, and for each I want to create a "report" of some ...
1
vote
1
answer
241
views
How do I get an F# fsx script to re-execute and re-pull SQL data each time it's called from C#?
I have written a simple C# web app that allows the user to input some data and then upon button click:
the data is saved to a local SQL db
an F# script is called to retrieve that data using ...
4
votes
1
answer
686
views
How to use Span in F# interactive?
I try to add reference to System.Memory by
#r "C:/Program Files/dotnet/shared/Microsoft.NETCore.App/2.1.5/System.Memory.dll"
But F# interactive still says The value or constructor 'Span' is not ...
4
votes
1
answer
508
views
F#: Why does script file not recognize module?
I create a new F# console application project in Visual Studio 2015
I create a simple new module file called Calc.fs like so:
module Calc
let add a b = a + b
I add an F# script file to the project ...
0
votes
0
answers
86
views
Function that has two arguments and I can create a file into
How can I define two functions in a given file system using f#script? A function that will have two arguments and will create a file into the root directory of the given file system. The first ...
3
votes
0
answers
524
views
I have a .fsx f# script file in Visual Studio, and i want to build an exe that executes it, how should i proceed?
I'm working with visual studio 2015.
I undestood that I have to create a console application project, then I added the scripts. Now i don't understand what I have to do.
my main is just 4 lines of ...
3
votes
1
answer
129
views
How to request UAC in fsi and fsharp script
I have a script:
open System
open System.IO
let fileSize path =
try
Some((new FileInfo(path)).Length)
with
| e ->
printfn "%A" e
None
let dirSize dir =
...
5
votes
1
answer
626
views
How to get correct resolution folder of F# Type Provider when referencing assemblies via #load?
I'm writing a type provider which allows the user to supply a configuration file to it. I use the TP's internal configuration object to identify the ResolutionFolder, which I use to get the fully-...
2
votes
1
answer
1k
views
#if - #else - #endif breaking F# Script
Using Visual Studio 2015 Update 3 and fsi.exe from F# v4.0 I' trying to run this script:
//error.fsx
#if INTERACTIVE
let msg = "Interactive"
#else
let msg = "Not Interactive"
#endif
let add ...
2
votes
1
answer
128
views
FSharp Reflection in fsx script - does the module define a variable of name foo?
If I have a module of name MyModule defined in an .fsx script and referenced from within another .fsx script; is it possible to determine at runtime if the module defines a variable foo?
I am trying ...
3
votes
2
answers
1k
views
Autocomplete F# script code in VSCode
I installed the Ionide-fsharp (1.9.1) package in VSCode (1.2.1) and started writing some example scripts from fsharpforfunandprofit.com. I expected to have autocomplete in the VSCode editor, but it ...
0
votes
1
answer
223
views
.fsx script ignoring a function call when I add a parameter to it
Alright, so I'm a happy fsx-script programmer, because I love how I can have the compiler shout at me when I do mistakes before they show up at runtime.
However I've found a case which really ...
4
votes
1
answer
805
views
F# Excel Interop: Marshal.GetActiveObject("Excel.Application") does not work
I am trying to use F# to automate some Excel tasks. I actually got two issues:
1. If I open a workbook using an Excel.Application instance, I would miss all the add-ins that would have been ...
11
votes
2
answers
3k
views
Can I install/reference packages from within an fsx file?
I'm trying to find a simple solution that isn't so much manual work to reference packages. inside a .fsx file.
LinqPad 4 lets me simply add nuget packages
no intellisense or autocompletion
deletes ...
0
votes
1
answer
81
views
Why are some functions available only in F# script files, not in source files?
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 ...
0
votes
2
answers
773
views
Infer the type information for any arbitrary CSV files?
I want to use the following console program to get the type information (not the data) of Csv type provider. The file name will be passed as a command line argument. However, it seems the CsvProvider&...
2
votes
2
answers
2k
views
Load a file into F#'s FSI - without using #load
I want to load a file from a .fsx script into into the F# Interactive Session but I can't use #load since I only want to load it if a certain condition is true.
Is there a function like FSI.LoadFile ...
-1
votes
1
answer
120
views
F# windowsforms application with custom class
I have a button class derived from Button()
with position attribute
namespace fgame15
open System
open System.Windows.Forms
open System.Drawing
module Game15Button =
type Game15Button(position:...
6
votes
2
answers
1k
views
What/where is get_Zero in F#'s int?
I'm just learning F#, and while playing at tryfsharp.org I noticed that if I change this code:
[0..100]
|> List.sum
to
["A"; "B"; "D"]
|> List.sum
I get the following error:
The type 'string' ...
2
votes
3
answers
789
views
F# environment integration (for scripting)
I like F# and I want to practice a little by writing some scripts for automation of some annoying task.
How do i interact with other programs the same way i can do from CMD or PowerShell
for example ...
2
votes
2
answers
325
views
F# Interesting Behavior of Curried Function
I have a function
// Will perform a given function twice
let twice f = (fun x -> f (f x))
Then I have something like.
// Take x add 1
let f x = x+1
Depending on how I call twice it behaves ...
0
votes
1
answer
1k
views
Mergesort Getting an Error in F#
let rec merge = function
| ([], ys) -> ys
| (xs, []) -> xs
| (x::xs, y::ys) -> if x < y then x :: merge (xs, y::ys)
else y :: merge (x::xs, ys)
let rec split = ...
-1
votes
1
answer
1k
views
F# Interactive Pass ParamArray of Functions
I'm trying to expand on James Hugard's post How do I plot a data series in F#? and I'm running into a glitch when using a variable number of function arguments. If I specifically name out the ...
0
votes
2
answers
1k
views
Cut a list by index n in F#
Trying to write a recursive function that will cut a list by n. Then return 2 lists. So if I pass
cut(2, [5;10;4;2;7]);;
val it : int list * int list = ([5; 10], [4; 2; 7])
I would like to get ...
1
vote
1
answer
107
views
F# type information
this simple function
let s =
function
| [] -> [[]]
| list -> []::list
has type ('a List List -> 'a List List). Thus, since 'a is generic, it accepts lists af arbitrary depth as ...
1
vote
2
answers
351
views
F# function - expected type differs from actual
I have been trying to write a curried function "multvec" which uses u=(u1, u2, ..., un) and v=(v1, v2, ..., vn) and outputs u1*v1 + u2*v2 + ... + un*vn. I think I have the logic mostly correct (at ...
7
votes
1
answer
1k
views
Use app.config from fsx file
Is it possible to use an app.config file from a F# script (fsx) file? If so, how? Where do I put the file and what will it be called?
0
votes
1
answer
446
views
Playing with F# types and getting lost
I have been doing a little reading on F# and decided to give it a try. I started with a somewhat involved example and I came up with and got lost immediately. I wonder if someone can share some ...
4
votes
3
answers
995
views
How to keep fsi.exe open after running
I have a bunch of F# scripts (fsx) that I use for my basic deployment needs. I just right click them and say "Run with F# interactive"
However, sometimes the script fails and I would like to keep the ...
8
votes
2
answers
6k
views
F#: Flattening a sequence of sequences into a single Seq
I am trying to build a single sequence that contains the contents of multiple files so that it can be sorted and then passed to a graphing component. However I am stuck trying to fold the contents of ...
2
votes
1
answer
2k
views
error FS1133: No constructors are available for the type 'List<'a>'
I created a type Person as follows which runs fine.
type Person =
{ First: string; Last : string }
override this.ToString() = sprintf "%s, %s" this.First this.Last
But when I try to make a ...
1
vote
2
answers
460
views
stemming of a word without Regex
Is it possible to stem words without using Regex in F#?
I want to know how can I write a F# function which inputs a string and stems it.
eg.
input = "going"
output = "go"
I can't find a way to ...
0
votes
3
answers
205
views
stopword removal in F#
I am trying to write a code to remove stopwords like "the", "this" in a string list etc.
I wrote this code:
let rec public stopword (a : string list, b :string list) =
match [a.Head] with
...
1
vote
4
answers
188
views
Curried functions f#
I have a question regarding two types int -> (int -> int) and (int -> int) -> int. What is the difference between these two?
I read here somewhere that the first one could be interpreted as a ...
1
vote
1
answer
587
views
f# spacing and mergesort
I have this code provided by my instructor. I am supposed to fix it by finding what type f# infers from mergesort. When I try to send to interactive i get an error . I asked my proffesor what was ...
0
votes
1
answer
488
views
convert text file content into string and pass as a function in F# [closed]
I want to read a text File and count the number of vowels in it. I want to know how to convert "ParseFile" content in to a string then pass as a variable to countVowels
Obviously, the way I am trying ...
7
votes
1
answer
7k
views
Cartesian product two lists [duplicate]
Possible Duplicate:
F# - cross product of two lists
Projecting a list of lists efficiently in F#
I have a function that takes two integer lists and returns a single list with all the cartesian ...
0
votes
4
answers
6k
views
Split list into two
I would like to implement a function that takes as input a size n and a list. This function will cut the list into two lists, one of size n and the rest in another list. I am new to this language and ...
11
votes
6
answers
4k
views
Merge two lists
I am looking to merge 2 lists in F# in a purely functional way. I am having a hard time understanding the syntax.
Let say I have a tuple ([5;3;8],[2;9;4])
When I call the function, it should return ...
4
votes
1
answer
445
views
F# Script SharePoint 2010 API doesn't work
I am trying something really simple in F# to try and test interaction with the SharePoint 2010 API. I think I am running into a general problem with F#. Is there anyway that an F# script can access ...
6
votes
2
answers
1k
views
IntelliSense in .fsx and dynamically loaded assemblies
When dynamically referencing assemblies in .fsx using #I and #r, VS highlights the following usages of imported types and writes "The namespace or module 'XXX' is not defined". Is it ok?
For example,...
0
votes
3
answers
945
views
How to invoke a Javascript function from F#
I am very new to F# and i do more work with Javascript.
I just want to know whether it is possible to call a javascript function from F#.
Of course this Question may not show minimum effort. But i am ...
8
votes
2
answers
2k
views
How to run a F# script in the context of C# Application
Is it easily possible to run a F# script from within (and in the context) of a C# Application (host).
With 'in the context' I mean the following should be true:
no separate process for the execution ...
0
votes
2
answers
111
views
Capture piped value (Noob Question)
I need to capture a value and don't know how to do it.
myData
|> Seq.count
How do I capture that count? I want to be able to do an if on it or whatever.
Thanks.
11
votes
1
answer
6k
views
Include files in an FSX file?
I use F# as a scripting language with FSI. Is there a way to include another fsx file in my script? I want to be able to break my scripts into multiple files for larger tasks.
Thanks.
0
votes
1
answer
724
views
F# scripting: Add new directory via #I
How could I make this work?
#I (__SOURCE_DIRECTORY__ + @"\bin\Release")
And second questions. Is it possible to do something like:
let path = __SOURCE_DIRECTORY__ + @"\bin\Release"
#I path
?
2
votes
1
answer
442
views
Using COM DLLs with FSI
Is there a way within FSI that I can reference and use registered COM components?
In a normal .fs compiled program I can simply reference the component in question and then open the relevant ...