仅依赖base包时GHC.Arr是否适用及文档缺失问题咨询
Hey there! Let's tackle your two questions about using arrays in Haskell with only the base package:
Is GHC.Arr suitable for your array needs?
Absolutely! GHC.Arr is part of the base package (it's a GHC-internal module included with base), so you can use it without needing to install any extra packages like array. It provides a solid array implementation with all the basic operations you'd expect:
- Creating arrays with bounds and key-value pairs (using functions like
array) - Indexing arrays with
(!) - Updating arrays with
// - Bounds checking with
bounds - Plus support for mutable arrays like
IOArrayandSTArrayif you need in-place modifications
Just keep in mind that GHC.Arr is a GHC-specific module, not part of the standard Haskell 98 spec. But if you're using GHC (which is the most common Haskell compiler), this won't be an issue. It's essentially the underlying implementation that the array package's Data.Array builds on, so it's fully capable of handling your array use cases.
Why isn't GHC.Arr listed in the base-4.11.0.0 Hackage docs?
Great question! Hackage's documentation for the base package typically prioritizes showing standard, non-GHC-specific modules (like Prelude, Data.List, etc.). Modules starting with GHC. are considered internal implementation details of the GHC compiler, so they're often hidden from the main Hackage docs for base.
Instead, you can find documentation for GHC.Arr in the official GHC documentation corresponding to your base version (base-4.11.0.0 ships with GHC 8.2.2). Even though it's not listed on Hackage, the module is absolutely part of base and safe to use if you're targeting GHC.
内容的提问来源于stack exchange,提问作者Leo Zhang

