3 ms·
> Why do I need to put <X, Y> in brackets after Map? [...] In F# and friends, there is no need Try: let foo (arg: list<'x>) : list<'x> = ... <inside
by a1369209993 6y ago
> Why do I need to put <X, Y> in brackets after Map? [...] In F# and friends, there is no need
Try:
let foo (arg: list<'x>) : list<'x> =
...
<inside foo somewhere>
let bar (arg: list<'x>) : list<'x> = ...
...
Is bar generic over a fresh type that happens to be named 'x, or is it a monomorphicly-typed local function that uses the type 'x that foo is generic over?
- uryga 6y agonot sure about F#, but in haskell it's the former, and you can switch to the latter with the -XScopedTypeVariables language extension. though IME you rarely (if ever) need it thanks to type inference.
- a1369209993 6y agoActually, on further consideration, you could restrict the ' to only occur where the type parameter is introduced, like so: List<X> foo(List<'X> inp) = ... List<X> bar(List<'X> xs) = ... # new X scoped to this declaration List<X> baz(List<X> xs) = ... # use foo's X ...