Open
Description
The section that discusses the printByte
function mentions (correctly) that F# will infer the input type based on usage, or will fall back to e.g. int
.
This time it will refuse to compile, because it has determined that it needs an int and now we've told it to also take a byte type as well. The former input has set the variable input type in stone and it duly refuses
You can actually make the function generic for any type that supports %i
by using the inline
keyword:
let inline printByte number =
printfn "%i" number
which creates a function as follows:
val inline printByte :
number: ^a -> unit
when ^a : (byte|int16|int32|int64|sbyte|uint16|uint32|uint64|nativeint|
unativeint)
Not sure if you want to add this in - but may be useful to know that F# can do this.
Metadata
Metadata
Assignees
Labels
No labels