Questions tagged [f#]

10876 questions
1

votes
1

answer
54

Views

The value or constructor is not defined

I have defined both records and created a union from them, but F# still complains that the constructor 'Food' is not defined. What is the problem? type Product = {Name : string; BasePrice: int} type Size = {Medium: int; Large: int} type Food = | Product of Product| Size of Size let food = Food({Name...
Denki
1

votes
1

answer
340

Views

How to translate this MSBuild script to F#/FAKE?

What is the translation of the following MSBuild script into F#/FAKE? None My main goal is to set a property in the topmost targets with different values (CurrentMode is either A or B) and consume it in the deepest target (Compile).
mu88
1

votes
2

answer
41

Views

How to use Entity Framework in-memory database in an F#?

I am trying to use Entity Framework Core with F# with the in memory database for a very simple use case: open System open Microsoft.EntityFrameworkCore type Position = { X: double Y: double } type Airport = { Id: Guid Name: string Position: Position } type MyContext = inherit DbContext new() = { inh...
Ehouarn Perret
1

votes
1

answer
65

Views

Using an accumulator to sum up numbers in F#

I'm trying to solve a problem that requires me to sum up 2 numbers but I have to use an accumulator in my function. This is the math formula: sum(m, n) = m + (m + 1) + (m + 2) + · · · + (m + (n − 1)) + (m + n) Here is what I have so far: let rec g (m, n) = let rec gAcc m n a = match n with |...
1

votes
1

answer
39

Views

Pipelining functions with different parameters in F#

I have the following code: type CustomerStatus = |Valid |Invalid type Customer = {Id:int; FirstName: string; LastName:string; Status: CustomerStatus} let checkCustomerFirstName (customers: Customer seq) = customers let checkCustomerLastName (customers: Customer seq) = customers let checkCustomerInB...
Jamie Dixon
1

votes
1

answer
41

Views

Extend the W algorithm to containers

I would like to extend the W algorithm to the inference of tuples and lists in F#, a priori, there are only two rules to add, which I did, however, the result is partially bad. Indeed, if I test a code like these: test = (8, 'Hello', 0.3) -- test :: (TInt, TString, TFloat) id :: a -> a id x = x...
Foxy
1

votes
1

answer
50

Views

F# : How to check asequence of sequences content?

I would like to generate a sequence of sequences of sets of tuple It's for generating coordinates of lines in board game (squares);horizontal lines,vertical lines, and the main 2 diagonal lines The one I created using list (using the generateLines function) works well. It generates the coordinates...
user43944
1

votes
1

answer
54

Views

How to consume this EF Core C# async method in F#?

I am using F# with Entity Framework and I can't get my head around consuming C# async methods from F#. Despite others SO answers related to similar issues can't really get my head around. Here is my attempt with the code below, initially synchronous: let getAirport (id: Guid) = use context = new MyC...
Ehouarn Perret
1

votes
3

answer
659

Views

The Http of FSharp.Data and proxy server

I'm creating a program to download web pages using the Http module of FSharp.Data. However, the module doesn't support setting http proxy server. In C# there is _httpWebRequest.Proxy = new System.Net.WebProxy('http://proxy.myCompany.com:80', true); I tried to download the file from https://github....
ca9163d9
1

votes
1

answer
172

Views

Creating a list or sequence of numbers up to a certain value in F#

Suppose I want to create a list or sequence of all cubic numbers under 5555, or fibonnacci numbers under 4500 - How would I do this? I can generate a list or sequence of these , but I don't know how to make them terminate after a certain point. In the case of the fibonacci sequence it is difficult...
Dr. John A Zoidberg
0

votes
4

answer
43

Views

How to add space after inputted Python name, when printing?

I'm a new Python coder, so please take it easy on me and don't get angry when I don't understand. I know this might seem abnormal, but I can't understand what is wrong with this code: name = input('What is your name?') print('Hello'+name) It prints 'HelloJoe' instead of 'Hello Joe', which I am aimin...
1

votes
1

answer
43

Views

How to define an extention method for a non-generic array?

I cannot figure out what is the correct syntax to define an extension method on a non-generic array. This question deals with generic arrays, but trying a similar construct for a byte array doesn't work. I have tried a lot of options: type Byte ``[]`` with type byte ``[]`` with type Byte array with...
Kapol
1

votes
1

answer
96

Views

What are the operators ==> and =?>?

I was reading F# code when I found two operators I was not aware of. 'Clean' ==> 'ResolveDependencies' ==> 'SetBuildNumber' =?> ('PatchAssemblyInfo', buildServer = TeamCity) I looked into the F# documentation page for the operators without success. I did not find anything about them. What are they?
aloisdg
1

votes
1

answer
45

Views

How to merge f string with b string in one line usage in Python

I can create b-sting this way: name_binary = b'Adam' but if I have variable like name='Adam' and I want to make at once usage of f-string and b-string: name_binary = fb'{name}' I get: File '', line 1 c = fb'{a}' ^ SyntaxError: invalid syntax I know that I can do: name_binary = name.encode('utf-8') B...
pbaranski
1

votes
1

answer
28

Views

how to define a measure as a multiple of another measure

I am attempting to define Isaron to be 43.2 times an Egg, but I am getting an exception: [] type Egg [] type Isaron = (43.2)*(Egg) error FS0618: Invalid literal in type How do I correctly define this measure?
1

votes
3

answer
83

Views

Pipeline one argument to multiple functions?

How can you pipeline one argument to multiple functions? For instance, if i wanted the tuple (2,5) to be passed to both fst and snd and then pass the result of each as two arguments to another function - this could be illustrated with the following hypothetical, non-working, code: (2,5) |> (fst & sn...
npp
1

votes
1

answer
76

Views

How can I unit test an Asynchronous method in F#?

I've got a method that returns a task I'm trying to test synchonously in F#. Here's the method, which is an implementation of a C# interface: member this.RunAsync(): System.Threading.Tasks.Task = async{ this._settings.LogSettings |> Seq.iter(fun settings -> this.clearLogs(settings)) |>...
reckface
1

votes
2

answer
81

Views

Using Packages without the F# Project Structure

Is there any way to just install a package in my system and have any .fs file be able to reference it? Is it possible to use F# Packages without following the Project Structure? All FSharp uses of external packages I have seen either make use of NuGet (for proper big projects) or reference a downloa...
tlgs
1

votes
1

answer
56

Views

F# : wrap tuples into multiple lines

Let's say I have a simple Tree : type Tree = | BinaryNode of Tree * int * Tree | Tip member this.Sum = match this with | Tip -> 0 | BinaryNode(left, value, right) -> left.Sum + value + right.Sum and I define a tree by : let tree = BinaryNode( BinaryNode( Tip, 2, Tip ), 1, BinaryNode( Tip, 3, Tip ))...
itminus
1

votes
1

answer
135

Views

F# This value is not a function

Playing with F# and it seems that i cannot find out what is wrong. FS0003 This value is not a function and cannot be applied. Did you forget to terminate a declaration? evaporator 25.0 10.0 10.0 let evaporator (volumeMl:double) (evapPerDaydouble:double) (threshold:double):int = let mutable count...
A191919
1

votes
2

answer
36

Views

Issue with SQL queries and Series / Type

Here is my code to request a DateTime*float from my SQL DB (I use : open FSharp.Data.TypeProviders) type FxTS = Series let get (req: RFxTS) = query { for d in db.Data_FXBFIX do where (d.Fxpair = (req.FxPair.ToString()) && (d.DatetimeUTC.Date >= req.Period.startDate) && (d.DatetimeUTC.Date Series.of...
Jeff_hk
1

votes
1

answer
54

Views

F# Seq<Seq<char>> convert to string

Playing with F# and trying to get from stringabcdefghijklmnop another string aeimbfjncgkodhlp. let input ='abcdefghijklmnop' let convertList (input:string)= input |> Seq.mapi(fun i ei-> i % 4, ei) |> Seq.groupBy (fst) |> Seq.map(fun (g,s)-> s |> Seq.map snd) let result = convertList input result In...
A191919
1

votes
2

answer
2.4k

Views

Convert a sequence of dictionary keys to a set

The following code lists the set of keys found in a dictionary sequence (each dict is basically a row from a database). (I want to convert the keys to a set so I can compare 2 db tables) for seqitem in tblseq do let keyset = seqitem.Keys |> Set.ofSeq // works correctly printfn '>>> List: %A; Ite...
BrendanC
1

votes
0

answer
559

Views

details for project could not be loaded

My first attempt with F# has yielded with the following exceptions: Severity Code Description Project File Line Suppression State Error Error occurred while restoring NuGet packages: The operation failed as details for project ConsoleApp1 could not be loaded. Error Assets file 'C:\...
1

votes
0

answer
44

Views

Cannot open viewcontroller - ios F# (performSegue and presentviewcontroller)

I'm trying to simply present a ViewController, however, this doesn't work using the PerformSegue method or the PresentViewController method, nothing seems to happen. I have verified using the debugger that the correct line of code is reached, I have also verified the names and IDs are correct. name...
Alk
1

votes
0

answer
53

Views

Prevent `using static` Directive with RequireQualifiedAccess

In F#, there is a .NET attribute that prevents programmers to use using static: Adding the [] attribute to a module indicates that the module may not be opened and that references to the elements of the module require explicit qualified access. For example, the Microsoft.FSharp.Collections.List modu...
MiP
1

votes
0

answer
29

Views

UICollectionViewController F#

I'm trying to implement the following in F#: public class SimpleCollectionViewController : UICollectionViewController { static NSString animalCellId = new NSString ('AnimalCell'); public override void ViewDidLoad () { base.ViewDidLoad (); CollectionView.RegisterClassForCell (typeof(AnimalCell), ani...
Alk
1

votes
0

answer
24

Views

Add viewcontroller for iOS app using F#

I just downloaded VS 2017 for MAC trying to build my iOS using Xamarin. With C# things sounds fine, but with F# things are not ok I can not create new viecontroller and can not assign any action for the elements in the only viewcontroller that generated automatically at startup. This is the screen I...
Hasan A Yousef
1

votes
0

answer
77

Views

How return JSON in ShouldInterceptRequest on android (it always return string)

When returning json from: override this.ShouldInterceptRequest(view:WebView, request:IWebResourceRequest) = let rows = Customer.fakeData 1 let st = Shared.jsonToStream(rows) new WebResourceResponse('text/json', 'UTF-8', st) It show on the page as an string, no a json object. I also try with 'applica...
mamcx
1

votes
0

answer
86

Views

Connect BLE device from F#

Since F# is not (yet) supported by .net native compiler, is there another process to connect a BLE device from an F# application? As far as I can see, 32feet uses UWP, and all other examples I found are also based on UWP. And as far as I know, UWP is based on the .net native copmpiler.
Peter Siebke
1

votes
0

answer
183

Views

Calling F# from python

I have a complex piece of F# client code which successfully accesses some webservices. The specification of the project has now changed and I wish to manipulate the data extracted from the webservices in python, instead of wasting time and energy on writing a python client I would like to access th...
CuriousPython
1

votes
1

answer
26

Views

Sending SSO cookies when doing an ajax call in websharper

I've created a website using WebSharper and has stumbled into a problem. I wish to integrate the site with VSTS REST API. To do that (seemlessly) I need to forward a session cookie. How do I do that in an WebSharper-Ajax call. My current implementation of the Ajax call prior to needing this looks li...
Rune FS
1

votes
1

answer
231

Views

How do I make an analog clock using winforms in F#?

I have to create an analog clock using winforms in F#. The clock needs also to have a label showing date and time in digital form. I have figured how make the label with time and date, as well as drawing the circle and the clockhands, but I'm having trouble with how i'm gonna implement the timer fun...
Chrizzar
1

votes
1

answer
89

Views

SizeforItematIndexPath in F# Xamarin

I'm trying to override the following method of the UICollectionViewFlowLayout in order to specify the size of my UICollectionViewCell : [MonoTouch.Foundation.Export('collectionView:layout:sizeForItemAtIndexPath:')] public virtual SizeF GetSizeForItem (UICollectionView collectionView, UICollectionVi...
Alk
1

votes
0

answer
54

Views

F# RProvider rworldmap joinCountryData2Map field, constructor or member 'joinCountryData2Map' is not defined

I am playing with F# RProvider and I am unable to make library plugin work. Rworldmap seems to be loaded successfully but F# doesn't recognize related functions like joinCountryData2Map. I am trying code from Mathias Brandewinder blog - Creating maps using R, Deedle and F# type providers I open thes...
Michal
1

votes
0

answer
111

Views

Custom UICollectionViewDelegateFlowLayout - Xamarin IOS

I'm trying to create a custom UICollectionViewDelegateFlowLayout in F#, similar to the one below in C#: public class CityViewDelegate : UICollectionViewDelegateFlowLayout { #region Application Access public static AppDelegate App { get { return (AppDelegate)UIApplication.SharedApplication.Delegate;...
Alk
1

votes
0

answer
74

Views

Why can't I install Deedle?

I downloaded a Git repository to another machine and I am having problems installing Deedle from NuGet. I get this message: Attempting to gather dependency information for package 'Deedle.1.2.5' with respect to project 'Fractal10', targeting '.NETFramework,Version=v4.5.2' Gathering dependency inform...
Soldalma
1

votes
0

answer
87

Views

redline errors in CODE for F# MVC

I just run dotnet new mvc -lang F# and got the template created. Once i run it using dotnet run it runs smoothly without errors. But, in MS Code, I see lots of error-like msgs, and lots of red lines, how to get red of them? I got the below error in the output: [18:18:28 INFO ] Logging to output at l...
Hasan A Yousef
1

votes
1

answer
242

Views

F# and Unity: Set.contains fails on simple structural equality test

I've run into a problem using Set.contains in F# running inside Unity. (Unity does not officially support F#, but they do support including .DLLs as Plugins to provide externally-compiled code which Scripts can access. This project includes the FSharp.Core.DLL inside Unity and works well. This is th...
anticrisis
1

votes
1

answer
58

Views

NSInvalidArgumentException : attempt to insert nil from objects[0]

I have a UIPageViewControllerDataSource initialised as follows: [] type FlatImagesPageViewDataSource() as x = inherit UIPageViewControllerDataSource() let mutable isinitialised = false let mutable flatImages : List = List.Empty let mutable parentView : UIPageViewController = null let mutable contr...
Alk

View additional questions