3 ms·
The error was my own. Only I couldn't figure out where exactly. Such errors can't be avoided. I need arrays for performance. If performance is no concern I ca
by jstimpfle 10y ago
The error was my own. Only I couldn't figure out where exactly.
Such errors can't be avoided. I need arrays for performance.
If performance is no concern I can use Maps, but I still need indexing ("partial functions") for architectural
reasons: separation of concerns - can't make "safe" graphs where everything holds a reference to everything "related".
I just don't buy the idea that partial functions can be avoided.
- pka 10y agoI.e. look at how PureScript does it [0]. Haskell could do the same. [0] https://pursuit.purescript.org/packages/purescript-arrays/3.0.1/docs/Data.Array#v:index https://pursuit.purescript.org/packages/purescript-arrays/3....
- jstimpfle 10y agoSure, I can use a Maybe variant, but the consequence would be that I wrap the whole program in a layer of maybes for cases that I "know" shouldn't happen but happened -- because I do make mistakes. Or in other words, an "AssertionMonad". No thanks, I'm perfectly fine with assertion errors (i.e. "Index out of bounds"). I just need help with finding my own errors. Stacktraces are a good thing.
- pka 10y agoI agree, stack traces are a good thing. For the time being, make a helper function: ixWithString :: String -> Int -> Array a -> a check the bounds inside and error out with a custom message when the index is outside the array bounds.