f#

Is it possible to define types that depend on each other and are defined in separated files?

扶醉桌前 提交于 2019-12-05 14:23:24
I am trying to implement a library with extended parsing capabilities. I decided that I will use fsyacc because I knew it from the university. Unfortunately I encountered following problem. I defined a class for the head of my grammar ( Head ) and place its implementation in a single file. Then I defined parser as: ... %start head %type <Head> head ... Fsyacc generates seeparated module ( Parser ). In order to succeed it has to be compiled in following order: Head.fs Parser.fs In order to make this library similar to what you can find in .NET I would like to add a static Parse method to Head .

How to set a Json response in suave webpart

烈酒焚心 提交于 2019-12-05 14:18:30
i'm begining with Suave and F#. I'm trying to pass a json serialized object in my webpart to get it in my response. In php i have this <?php header('Access-Control-Allow-Credentials:true'); header('Access-Control-Allow-Headers:Content-Type, Accept'); header('Access-Control-Allow-Methods:GET, POST, PUT, DELETE, OPTIONS'); header('Access-Control-Allow-Origin:*'); ?> { "player1Key":"hdegftzj25", "gameKey":"aegfhzkfszl74852" } and with this i get my json object, then i tried to do the same with Suave and Newtonsoft.Json type gameCreate= { player1Key : string gameKey: string } let create= {

F# WPF: Handling click events in ListBox

走远了吗. 提交于 2019-12-05 14:14:49
I'm trying to create a simple task scheduler using F# and WPF. It's basically just a list of tasks where every task has a 'Delete' button. Handling button clicks outside of the list is not a problem -- this can be handled with a regular command. However handling a button click in the list item is not straightforward. I tried using RelayCommand described here with binding routed to parent, but the sender object is always null (I expected it to be the task object from the collection). Also tried attaching a property as recommended here , but couldn't make it work. How do I assign an event

How do you declare the values of a dictionary entry as mutable?

对着背影说爱祢 提交于 2019-12-05 14:11:37
问题 The Google yields plenty of example of adding and deleting entries in an F# dictionary (or other collection). But I don't see examples to the equivalent of myDict["Key"] = MyValue; I've tried myDict.["Key"] <- MyValue I have also attempted to declare the Dictionary as Dictionary<string, mutable string> as well several variants on this. However, I haven't hit on the correct combination yet... if it is actually possible in F#. Edit: The offending code is: type Config(?fileName : string) = let

Any difference between t<'a> and 'a t in F#?

一世执手 提交于 2019-12-05 13:53:12
问题 Is there any difference in meaning between t<'a> and 'a t in F#? Can they be used interchangeably even after declaration? 回答1: There is no difference, and yes, they can be used interchangeably even after declaration. But do note the F# Component Design Guidelines recommendation (Section 4.2): Consider using the prefix syntax for generics ( Foo<T> ) in preference to postfix syntax ( T Foo ), with four notable exceptions ( list , option , array , ref ). F# inherits both the postfix ML style of

Extension methods for F# tuples

放肆的年华 提交于 2019-12-05 13:34:07
Is it possible to write extension methods for F# tuples? For example, to add instance methods .Item1 and .Item2 (like System.Tuple) which are equivalent to calling fst and snd for 2-tuples? Not perfect but I'm using this. (I borrowed original code from http://www.fssnip.net/6V and added small modification.) [<AutoOpen>] module TupleExtensions = type System.Tuple with static member Item1(t) = let (x,_) = t in x static member Item1(t) = let (x,_,_) = t in x static member Item1(t) = let (x,_,_,_) = t in x static member Item1(t) = let (x,_,_,_,_) = t in x static member Item1(t) = let (x,_,_,_,_,_)

Why is my Trie lookup slower than that of the standard F# Map's?

倖福魔咒の 提交于 2019-12-05 13:30:26
So, I just ported the Trie from OCaml. Unfortunately, it runs slower than the standard Map in terms of tryFind. I don't understand this - the trie seems like it should be faster. Is F#'s code libraries built in some special way as to make them faster than the code that the user typically deploys? Here's the code - [<RequireQualifiedAccess>] module Trie type Node<'k, 'v when 'k : comparison> = { TrieMap : Map<'k, Node<'k, 'v>> TrieKvp : ('k list * 'v) option } member inline x.IsEmpty = x.TrieKvp.IsNone && x.TrieMap.IsEmpty let inline make map kvp = { TrieMap = map TrieKvp = kvp } let inline

Redistributable version of FSharp.Core.dll?

感情迁移 提交于 2019-12-05 13:17:37
I have developed a commercial extension for the Unity3D game engine in F#, it's a piece of code which extends the editor with advanced node/graph editing features. F# is perfect for this due to the nature of immutability and DU's. But, to my question: I realized that the license for the FSharp.Core.dll which comes with Microsoft .NET/Visual Studio probably doesn't allow you to re-distribute it with a commercial project? How would I go about finding out if this is the case or not, and if it's not is there any way to create my own compiled version of FSharp.Core.dll which would run on Unity3D?

Comparison Of Nemerle and F# For Functional On .Net

[亡魂溺海] 提交于 2019-12-05 13:09:30
问题 Community Wiki Question: Pursuant to this question: What are the benefits of using Scala in .Net? another question comes to mind. Can anyone lay out the comparative advantages (and disadvantages) of Nemerle and F# for functional development on the .Net platform? I've just looked at Nemerle in passing. It sounds like it kind of plays in the same ballpark as F# so I was wondering what differences there are other than the obvious syntax differences and the big advantage F# has of being backed by

short-cutting equality checking in F#?

家住魔仙堡 提交于 2019-12-05 12:47:35
In F#, the equality operator (=) is generally extensional, rather than intensional. That's great! Unfortunately, it appears to me that F# does not use pointer equality to short-cut these extensional comparisons. For instance, this code: type Z = MT | NMT of Z ref // create a Z: let a = ref MT // make it point to itself: a := NMT a // check to see whether it's equal to itself: printf "a = a: %A\n" (a = a) ... gives me a big fat segmentation fault[*], despite the fact that 'a' and 'a' both evaluate to the same reference. That's not so great. Other functional languages (e.g. PLT Scheme) get this