f#

Token access, reuse and auto refresh within the SDK

寵の児 提交于 2019-12-23 04:17:11
问题 Coming from C# and other languages, and new to F# and trying to port an SDK Library that I built in an OO language. The SDK is responsible for retrieving access token first, setting on a static field and then setting a specific interval to continuosly refresh the token before it's expiry. The token is set as static field on the Authentication class and is updated every time before it reaches expiry. Then other actors within the SDK reach out to Authentication class, read it's static field

F# - Breaking a List into Concatenated Strings by an Interval

那年仲夏 提交于 2019-12-23 03:44:13
问题 I have a list of email addresses, and I need to send an email notification to each address. I'd like to do this in blocks of 25 addresses at a time. Is there any quick way in a functional language like F# to "fold" (concatenate) 25 emails addresses together... each separated by a semicolon. I know there is the String.Split method in .NET, but I need to concat 25 at a time. What is the most elegant way to perform this in F#? 回答1: Here's a way to break into groups of at most N: // break a

ExcelDna F# and optional arguments

前提是你 提交于 2019-12-23 03:37:17
问题 For scalar (i.e. non array-like) optional arguments, I would use this pattern : [<ExcelFunction(Category= "Test", Description= "Test optional arguments.")>] let test_test1 ([<ExcelArgument(Description= "Optional. This is a double. Default is 42.0.")>] arg1 : obj) : double = match arg1 with | :? ExcelMissing -> 42.0 // the argument was missing | :? double as d -> d // the argument was a double | _ -> -1.0 // otherwise I am not sure if this code is "idiomatic" within Excel-Dna / F# but it seems

Can you encapsulate multi case discriminated unions?

蓝咒 提交于 2019-12-23 01:02:36
问题 I see that you can enforce constructor usage of single-case discriminated unions, can you do the same with multi-case? for example type MemberId = | MemberId of int | MemberGuid of Guid I'm currently trying in the fsi like this val create : int -> T option val create : Guid -> T option but I'm guessing like C#, F# won't allow you to overload based on return type for the unwrap: val value : T -> string Edit --------------- MemberId.fsi = module MemberId open System type _T val createId : int -

What's wrong with my tree traversal code?

混江龙づ霸主 提交于 2019-12-22 19:42:16
问题 I have a simple tree, defined thusly: type BspTree = | Node of Rect * BspTree * BspTree | Null I can get a collection of leaf nodes (rooms in my tree "dungeon") like this, and it seems to work: let isRoom = function | Node(_, Null, Null) -> true | _ -> false let rec getRooms dungeon = if isRoom dungeon then seq { yield dungeon } else match dungeon with | Node(_, left, right) -> seq { for r in getRooms left -> r for r in getRooms right -> r } | Null -> Seq.empty But now I'm trying to get

What's wrong with my tree traversal code?

╄→尐↘猪︶ㄣ 提交于 2019-12-22 19:42:13
问题 I have a simple tree, defined thusly: type BspTree = | Node of Rect * BspTree * BspTree | Null I can get a collection of leaf nodes (rooms in my tree "dungeon") like this, and it seems to work: let isRoom = function | Node(_, Null, Null) -> true | _ -> false let rec getRooms dungeon = if isRoom dungeon then seq { yield dungeon } else match dungeon with | Node(_, left, right) -> seq { for r in getRooms left -> r for r in getRooms right -> r } | Null -> Seq.empty But now I'm trying to get

Difference between treatment of ambiguous generic interfaces by F# between VS 2012 and VS 2015 leading to compile errors in the latter

瘦欲@ 提交于 2019-12-22 17:56:53
问题 (Note: Question updated with full reproducible example) After migrating an F# project from VS 2012 to VS 2015 I receive an error on certain usages of interfaces. In particular it happens where a type implements two generic interfaces. I know this is not allowed in F# directly, but this type comes from C#. To reproduce the problem: 1. type definition in C#: Paste this in some class library. public interface Base { } public interface IPrime<T> : Base { T Value { get; } } public interface IFloat

What am I doing wrong in chunking a list in F#

不打扰是莪最后的温柔 提交于 2019-12-22 14:54:35
问题 F# doesn't come easy to me. The following piece of code is supposed to chunk a list. I have no idea what the problem is. Please help. let chunk items chunkSize = let folder = fun state x -> match state with (reversedResult, reversedChunk) -> if reversedChunk.Length < chunkSize then (reversedResult, x::reversedChunk) else ((reversedChunk |> List.rev)::reversedResult, [x]) let alsmostDone = items |> List.fold folder ([], []) match alsmostDone with | (reversedResult, []) -> reversedResult |>

Do config files I'm referencing need to be in a project's home directory?

馋奶兔 提交于 2019-12-22 14:54:21
问题 I'm trying to store connection string and credentials data in a .config file. I can't push the config with the connection/credentials to a repo; the config will be in a secure, synced folder that isn't the home directory. I can store the connection/credentials in the app.config file in the home directory and access it with the FSharp.Configuration library: type connection = AppSettings<"app.config"> but if I try to access a config in a different directory open System.IO open FSharp

T4 with languages other than C# and VB

喜欢而已 提交于 2019-12-22 12:23:33
问题 Is it posible to write T4 templates in other .NET languages? In particular I'm interested in F# and IronPython. 回答1: The doc stipulates that only VB and C# are supported: T4 Template Directive, see the language attribute. 回答2: I was complaining about this on twitter some time ago. It seems reasonable - afterall, T4 is just using CodeDOM provider! Anyway, Michael Hutchinson (from Mono team) suggested using the implementation in Mono, which should be extensible. I didn't look into that further,