f#-interactive

summing elements from a user defined datatype

馋奶兔 提交于 2020-01-06 05:00:05
问题 Upon covering the predefined datatypes in f# (i.e lists) and how to sum elements of a list or a sequence, I'm trying to learn how I can work with user defined datatypes. Say I create a data type, call it list1: type list1 = A | B of int * list1 Where: A stands for an empty list B builds a new list by adding an int in front of another list so 1,2,3,4, will be represented with the list1 value: B(1, B(2, B(3, B(4, A)))) From the wikibook I learned that with a list I can sum the elements by doing

F# FSI, Change working directory

女生的网名这么多〃 提交于 2020-01-04 05:12:09
问题 I have the following file located in a "New Folder" of Desktop: // File location: "C:\Users\my_user_name\Desktop\New folder\AddOne.fs" // module internal AddOneModule let AddOneFunction x = x + 1 I can access this file by using #load on the full path name using FSI F# Interactive. Microsoft (R) F# Interactive version 4.1 Copyright (c) Microsoft Corporation. All Rights Reserved. For help type #help;; > #load "C:\Users\my_user_name\Desktop\New folder\AddOne.fs";; //[Loading C:\Users\my_user

Embedding F# Interactive Example Throwing Exception from FSharp.Compiler.Service

扶醉桌前 提交于 2020-01-03 09:59:49
问题 I am working through the Embedding F# Interactive example from http://fsharp.github.io/FSharp.Compiler.Service/interactive.html but am having an issue with the following line throwing an exception: let fsiSession = FsiEvaluationSession.Create(fsiConfig, allArgs, inStream, outStream, errStream) The exception thrown is: "An unhandled exception of type 'System.Exception' occurred in FSharp.Compiler.Service.dll Additional information: Error creating evaluation session: StopProcessing null" My

Embedding F# Interactive Example Throwing Exception from FSharp.Compiler.Service

孤街浪徒 提交于 2020-01-03 09:58:07
问题 I am working through the Embedding F# Interactive example from http://fsharp.github.io/FSharp.Compiler.Service/interactive.html but am having an issue with the following line throwing an exception: let fsiSession = FsiEvaluationSession.Create(fsiConfig, allArgs, inStream, outStream, errStream) The exception thrown is: "An unhandled exception of type 'System.Exception' occurred in FSharp.Compiler.Service.dll Additional information: Error creating evaluation session: StopProcessing null" My

How to do typeof of a module in a fsx file?

老子叫甜甜 提交于 2019-12-24 01:58:09
问题 Let's say I have a Foo.fsx script that contains this code: module Bar = let foobar = "foo"+"bar" open Bar let a = System.Reflection.Assembly.GetExecutingAssembly() let ty = a.GetType("Foo.Bar") // but it returns null here How can I achieve that? Thanks! 回答1: This is a tricky question, because F# interactive compiles all types into types with some mangled names (and the executing assembly can contain multiple versions of the same type). I managed to do it using a simple trick - you'd add an

F# Interactive CsvProvider not defined

允我心安 提交于 2019-12-24 00:34:19
问题 I'm loading FSharp.Data in the interactive console. The library is loaded without any problem: > #r "FSharp.Data.dll";; --> Referenced 'C:\Users\pw\AppData\Local\Temp\FSharp.Data.dll' (file may be locked by F# Interactive process) > open FSharp.Data;; However, when I'm trying to initialize CsvProvider (defined in FSharp.Data ) I get the error message saying the type is not defined: > type Stocks = CsvProvider<"C:\Users\pw\Downloads\msft.csv">;; type Stocks = CsvProvider<"C:\Users\pw\Downloads

F# Convert 'a discriminated union to string

﹥>﹥吖頭↗ 提交于 2019-12-23 19:26:57
问题 I'm trying to convert a discriminated union to string but I don't understand why this code is not working. type 'a sampleType = | A of 'a | B of 'a let sampleTypeToString x = match x with | A (value) -> string value | B (value) -> string value This is the fsharp interactive output sampleTypeToString A(2);; Stopped due to error System.Exception: Operation could not be completed due to earlier error Successive arguments should be separated by spaces or tupled, and arguments involving function

Error FS0752 in F# declaration of a map over list of functions

点点圈 提交于 2019-12-23 12:08:54
问题 I would like to execute a list of functions over a list of corresponding values: let f1 x = x*2;; let f2 x = x+70;; let conslist = [f1;f2];; let pmap2 list1 list2 = seq { for i in 0..1 do yield async { return list1.[i] list2.[i] } } |> Async.Parallel |> Async.RunSynchronously;; Result: seq { for i in 0..1 do yield async { return list1.[i] list2.[i] } } ----------------------------------------------^^^^^^^^^ stdin(213,49): error FS0752: The operator 'expr.[idx]' has been used an object of

F# interactive, API restriction on dll referencing

别说谁变了你拦得住时间么 提交于 2019-12-23 09:32:04
问题 How do you solve the error message that looks like this? `Binding session to 'C:\Program Files (x86)\NLog\.NET Framework 4.0\NLog.dll'... error FS0193: API restriction: The assembly 'file:///C:\Program Files (x86)\NLog\.NET Framework 4.0\NLog.dll' has already loaded from a different location. It cannot be loaded from a new location within the same appdomain. Code that triggers it, might look like this: #r @"..\packages\NLog.2.0.0.2000\lib\net20\NLog.dll" NLog.Config.SimpleConfigurator

how to add third party dll reference to F# project?

徘徊边缘 提交于 2019-12-21 07:34:16
问题 I'm adding a third party dll reference to my F# project. I added the dll in references and when I use this i.e highlight the code and do Alt+Ent, I get the error "The namespace or module 'AZROLESLib' not defined." Am I missing some thing. 回答1: In short, you have to use #r "/path/to/AZROLESLib.dll" in order that F# Interactive recognizes and loads the dll file. Adding a dll reference helps Visual Studio to find correct libraries when compiling the project, but it has nothing to do with F#