I just ran into an issue: when I try to access a private or internal value from an inline function, I get the error "The value 'xxx' was marked inline but its implementation makes use of an internal or private function which is not sufficiently accessible". While logical, I wonder if anyone has a good work around. The best thing I can think to do is place the values publicly in a nested module and just hope no-one goes poking around (which I'm not too worried about anyway, since these values are immutable). I suppose reflection is an option, but without being able cache calls (using... private delegates) the performance hit is too much.
相关问题
- F#: Storing and mapping a list of functions
- Multiplying a list of tuples by a tuple in F#
- Multiplying a string in F#
- F# odd pattern matching issues
- Why doesn't bindingRedirect affect FSharp.Core
相关文章
- FSharp.Data.JsonProvider - Getting json from types
- Signing an F# Assembly (Strong name component)
- Learning F#: What books using other programming la
- fsc.exe is very slow because it tries to access cr
- Extension methods for specific generic types
- F# Object Initialization with a Constructor
- F# Lazy Evaluation vs Non-Lazy
- When to use interfaces, and when to use higher ord
Short answer: no, since the value will be inserted inline into the call-site, it can't use private values and there's no real way to work around it.
Longer answer: if you don't mind writing incredibly ugly code and you can handle the overhead of a few method calls per use, one alternative would be to create a dynamic implementation (e.g.
OperatorIntrinsics.AbsDynamicTableImpl
in the core library), which can be private. You can then wrap the dynamic implementation in a public opaque generic method (e.g.OperatorIntrinsics.AbsDynamic<'T>
), and then create an inline value which adds the proper type constraints and defers to the dynamic implementation (e.g.let inline abs< ^t when ^t : (static member Abs : ^t -> ^t)> x = AbsDynamic x
). Now when you inlineabs
you just see a call toAbsDynamic
but none of the further implementation details. In most cases I would expect this to be a much worse solution than just making your value public instead of private.