f#

F# - Understanding types that use generics

匆匆过客 提交于 2020-06-23 16:07:44
问题 I am having an F# exam in 10 days and as I am currently doing old exam sets, I ran into a problem understanding generics and especially types that have two polymorphic arguments. The questions should be rather easy to solve, but how it works syntactically, I am not sure. The old exam question is as follows: The following type Sum<'a,'b> comprises two different kinds of values type Sum<'a,'b> = | Left of 'a | Right of 'b Now I need to write two values of type Sum<int list, bool option> , one

F# - Understanding types that use generics

独自空忆成欢 提交于 2020-06-23 16:06:31
问题 I am having an F# exam in 10 days and as I am currently doing old exam sets, I ran into a problem understanding generics and especially types that have two polymorphic arguments. The questions should be rather easy to solve, but how it works syntactically, I am not sure. The old exam question is as follows: The following type Sum<'a,'b> comprises two different kinds of values type Sum<'a,'b> = | Left of 'a | Right of 'b Now I need to write two values of type Sum<int list, bool option> , one

F# - Understanding types that use generics

ぐ巨炮叔叔 提交于 2020-06-23 16:06:09
问题 I am having an F# exam in 10 days and as I am currently doing old exam sets, I ran into a problem understanding generics and especially types that have two polymorphic arguments. The questions should be rather easy to solve, but how it works syntactically, I am not sure. The old exam question is as follows: The following type Sum<'a,'b> comprises two different kinds of values type Sum<'a,'b> = | Left of 'a | Right of 'b Now I need to write two values of type Sum<int list, bool option> , one

F# - Understanding types that use generics

半腔热情 提交于 2020-06-23 16:05:48
问题 I am having an F# exam in 10 days and as I am currently doing old exam sets, I ran into a problem understanding generics and especially types that have two polymorphic arguments. The questions should be rather easy to solve, but how it works syntactically, I am not sure. The old exam question is as follows: The following type Sum<'a,'b> comprises two different kinds of values type Sum<'a,'b> = | Left of 'a | Right of 'b Now I need to write two values of type Sum<int list, bool option> , one

deserialization issue, with json.net, in F#

帅比萌擦擦* 提交于 2020-06-16 17:00:33
问题 I have a simple object to deserialize, but I do not understand the error I get. The code is the following: open System open Newtonsoft.Json type r = { Timestamp: DateTime Currency: string PreviousDeposited: int64 option PreviousWithdrawn: int64 option PreviousTransferIn: int64 option PreviousTransferOut: int64 option PreviousAmount: int64 option TransferIn: int64 option TransferOut: int64 option Amount: int64 option PendingCredit: int64 option PendingDebit: int64 option ConfirmedDebit: int64

Create a list of custom type in F# and create two sequences of that list

我与影子孤独终老i 提交于 2020-05-09 17:19:32
问题 I have created my own type in F# called Accounts and I have then created objects for each account. type Account() = let AccountNumber = "" let mutable Balance:float = 0.0 Every account has two fields, AccountNumber (string) and Balance (float). I have then created an object for every account that holds the AccountName and the Balance. let acc1 = new Account() acc1.Insert("John",10.0) let acc2 = new Account() acc2.Insert("Mike",50.0) How do I create a list that holds each account (object)? I

Comparing two objects with default IComparable implementation with F# Reflection

橙三吉。 提交于 2020-04-16 05:47:22
问题 Given two objects in F#, is there a way to use their IComparable method to compare them, assuming they are both of the same sub-type and that IComparable is implemented for their common sub-type. What I am trying to achieve in pseudo-code : let tycompare (o1 : obj) (o2 : obj) : int option = let (ty1, ty2) = (o1.GetType(), o2.GetType()) if ty1 <> ty2 then None else if IComparable is implemented on ty1 then o1.CompareTo(o2) |> Some else None I am aware of this post but I do not think it helps

Establish Units of Measure Relationships With a Quantity of Another Unit

99封情书 提交于 2020-04-07 04:38:22
问题 I realize that you can express relationships with dimensions of units, like [<Measure>] type cc = cm^3 and perform meaningful calculations later. Given some unit of measure type, [<Measure>] type m Is it possible to define a unit in a relationship with a quantity of another unit? For example, // doesn't compile [<Measure>] type mm = 0.001<m> // later let length = 500.0<mm> let length2 = 0.5<m> printfn "%A" (length = length2) // prints true 回答1: In short: no. Units of measure are annotations

Establish Units of Measure Relationships With a Quantity of Another Unit

别说谁变了你拦得住时间么 提交于 2020-04-07 04:34:45
问题 I realize that you can express relationships with dimensions of units, like [<Measure>] type cc = cm^3 and perform meaningful calculations later. Given some unit of measure type, [<Measure>] type m Is it possible to define a unit in a relationship with a quantity of another unit? For example, // doesn't compile [<Measure>] type mm = 0.001<m> // later let length = 500.0<mm> let length2 = 0.5<m> printfn "%A" (length = length2) // prints true 回答1: In short: no. Units of measure are annotations

Purpose of tick (apostrophe) in F# value names?

帅比萌擦擦* 提交于 2020-03-21 11:33:54
问题 I'm going through a tutorial on Function Composition, and I keep seeing the ' operator used at the end of a value declaration. I know that it means a generic when it precedes a parameter, but what does it mean when you see it like: let add x y = x + y let myFunc' = add 10 The only thing I can see is that the ' is just another character in the identifier. Is that right? Because if I use that same example, using myFunc gives a not defined error, where myFunc' does resolve. 回答1: Yes, as @Lee