f#

“let is unfinished. expect an expression” error. I don't see where though

扶醉桌前 提交于 2019-12-12 15:12:58
问题 open System let highLowGame () = let rng = new Random(); let secretNumber = rng.Next() % 100 + 1 let rec highLowGameStep () = printfn "Guess a number: " let guessStr = Console.ReadLine() let guess = Int32.Parse(guessStr) match guess with | _ when guess > secretNumber -> printfn "Too high!" highLowGameStep () | _ when guess = secretNumber -> printfn "You got it!" () | _ when guess < secretNumber -> printfn "Too low!" highLowGameStep () [<EntryPoint>] let main argv = highLowGame () 0 // return

Embed an application icon using WPF and F#

喜欢而已 提交于 2019-12-12 15:04:38
问题 How to embed an application icon into application.exe using WPF and F#? I did not find it anywhere. 回答1: I think the approach is the same for WPF and WinForms, which in F# means manually! Please see this answer. You could also looks at FsEye's source for reference (it's done in WinForms), see line 39 of http://code.google.com/p/fseye/source/browse/tags/1.0.0-final/FsEye/FsEye.fsproj, the file http://code.google.com/p/fseye/source/browse/tags/1.0.0-final/FsEye/IconResource.fs, and line 23 of

Creating more than one root type with generative type provider

半世苍凉 提交于 2019-12-12 15:03:30
问题 Generative type providers seem to have an issue with having more than one root type. Complete repro is available here: https://gist.github.com/dsevastianov/46d1a8495c4af46a9875. Following example #r @"SampleProvider.dll" type Birch = Sample.Sample<"birch"> type Elm = Sample.Sample<"elm"> let birch = Birch.birch() let elm = Elm.elm() elm.Branches <- ([|Elm.elm()|]) fails at compile time (not at design time): FSC: error FS2014: A problem occurred writing the binary 'obj\Debug\Tests.dll': Error

F#: how to specify static overload to use?

久未见 提交于 2019-12-12 14:42:57
问题 I have two classes declared in C# code: public class A { public static bool TryParse(string value, out A result) { ... } } public class B : A { public static bool TryParse(string value, out B result) { ... } } While calling B.TryParse from C# isn't problem, because correct overload is determined by out parameter type, which should be declared in advance. As out parameter is transformet to part of result in F#, we got two function with same parameter signature... And call from F# causes A

Order of type constraints in F#

 ̄綄美尐妖づ 提交于 2019-12-12 14:13:49
问题 This works in F#4.0: type Something<'a, 'b when 'b :> seq<'b>>() = This doesn't: type Something<'b when 'b :> seq<'b>, 'a>() = Unexpected symbol ',' in type name. Expected '>' or other token. What's the reason that the order of the type constraint matter? 回答1: Because it is in the spec - the relevant part is this (from the start of section 5): typar-defns:= < typar-defn, ..., typar-defn typar-constraints_opt> the constraints need to go at the end. In this typar-constraints must always start

Emitting Generated Types in F# type providers

谁说我不能喝 提交于 2019-12-12 14:00:27
问题 I have created a simple generating type provider that takes the path to an assembly at reorganizes the types, to bring them under the type providers namespace, (sort of Internalising if you like). The link to the code concerned is here https://github.com/colinbull/Playground Now the types seem to be provided correctly, let[<Literal>]assemblyPath = @"D:\Appdev\Playground\SimpleLib\bin\Debug\SimpleLib.dll" type T = Inno.InternalisingProvider<assemblyPath> type C = T.Class1 [<EntryPoint>] let

F# quotations on Windows Phone

瘦欲@ 提交于 2019-12-12 13:33:46
问题 I'm using Daniel Mohl's F# templates for Windows phone, but it seems the bundled FSharp.Core doesn't have some of the quotations code. I'm trying to port this code from regular .NET: open System.ComponentModel open Microsoft.FSharp.Quotations open Microsoft.FSharp.Quotations.Patterns [<AbstractClass>] type ViewModelBase() = let propertyChanged = new Event<_, _>() let toPropName expr = match expr with | PropertyGet(a, b, list) -> b.Name | _ -> failwith "Unsupported: " + expr.ToString()

Scala's equivalence to |> in F# or ->> in Clojure

那年仲夏 提交于 2019-12-12 13:17:45
问题 In Scala, when I have this expression f1 ( f2 ( f3 (p))) Is there a way that I can use something like in F# p |> f3 |> f2 |> f1 or Clojure? (->> p f3 f2 f1) 回答1: If you want to write it yourself without using external libraries, implicit class Pipe[T](x: T) { def |> [U](f: T=>U): U = f(x) } So, this implicit class pattern is used for extension methods. It's shorthand for the "pimp my library" pattern: class Pipe[T](x: T) { /*extension methods here*/ } implicit def anyToPipe[T](x: T) = new

Why is F# printfn not implemented in terms of Console.WriteLine?

喜夏-厌秋 提交于 2019-12-12 13:03:32
问题 I noticed an unexpected behavior when using F# printfn. It seems to break up the format string into chunks and call Console.Write multiple times for each call to printfn. I would expect it to format the entire string and then call Console.WriteLine once. I noticed this because I am intercepting the standard Console Output using Console.SetOut call with my own TextWriter which tries to prefix every line of output with a time stamp and some additional custom text. What gives? 回答1: Here's my

Why is Async.RunSynchronously hanging?

前提是你 提交于 2019-12-12 13:02:01
问题 In my f# project, I'm calling a c# library that returns me a Task. When I try to do this in my f# project, nothing happens. let str = getName() |> Async.AwaitTask |> Async.RunSynchronously However, if I update my code to use an async workfolow, it doesn't hang anymore. What am I doing wrong when calling Async.RunSynchronously? async { let! str = getName() |> Async.AwaitTask //Do something with str } 回答1: In your second example you just build async workflow, but don't actually run it. It is