Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I pass arguments with units to F# types?

Suppose I have defined a unit of measure:

[<Measure>] type Blob

And I want a type that takes a value in Blobs per second as a constructor argument:

type Something(flowRate:double<Blob/s>) = ...

F# throws a wobbly on this - "double does not expect any type arguments, but here is given 1 type argument"

I understand the message. I'd have thought it was obvious what I was trying to do, though I acknowledge that the syntax probably is verifiably wrong. Question is, how do I express this relationship in code?

like image 294
Tom W Avatar asked Nov 10 '10 19:11

Tom W


People also ask

Can we pass a variable number of arguments to a function?

Yes you can pass variable no. of arguments to a function.

What is F next?

F Next Dusting Powder is a combination medicine used to treat various types of fungal skin infections. It minimizes symptoms of skin infection such as redness, swelling, itching, etc., by acting against the infection-causing microorganisms. 622 people viewed this recently.

How do you pass a positional argument in Python?

Functions can accept a variable number of positional arguments by using *args in the def statement. You can use the items from a sequence as the positional arguments for a function with the * operator. Using the * operator with a generator may cause your program to run out of memory and crash.


1 Answers

As the message (sort of) indicates, doubles aren't measure-generic. Try float<Blob/s> instead. It's a bit strange, since float is a type synonym for type double. However, type float<[<Measure>]'t> is in some ways its own separate type. A similar problem occurs with single vs. float32, int32 vs. int, and int8 vs. byte. Section 9.7 of the spec partly covers this information.

It's especially confusing since you can't define your own types which differ only in their measure arity:

type T = class end
type T<[<Measure>]'t> = class end //' Duplicate definition of type T
like image 150
kvb Avatar answered Oct 06 '22 22:10

kvb