by Mathnerd314 · 10y ago · 0 comments
So you could write
case readIntArray# v (k +# 1#) realWorld# of (# vkp, _ #) ->
case readIntArray# v (k -# 1#) realWorld# of (# vkm, _ #) ->
case vkp <# vkm of
0# -> ...
1# -> ...
with syntax sugar reasonably close to V ! (k+1) < V ! (k-1).The problem is the state tokens; I ignored them by using realWorld# and _ above, but that makes the code not referentially transparent. So in practice, Haskell always passes them around in a monad (Except in all the core libraries, which use things like accursedUnutterablePerformIO to go back down to the thunk level: https://github.com/haskell/bytestring/blob/master/Data/ByteS...). But reads are (mostly) pure so it shouldn't break anything to provide a pure interface.
Alternatively, the verbosity can be seen as a syntax problem, with the corresponding solution of a better do-notation: https://www.reddit.com/r/haskell/comments/4dsb2b/thoughts_on...
so you'd get something like
(x,l0) <- if (<- v ! (k-1)) < (<- v ! (k+1)) ...
(again using ! for readArray, which has some impracticalities)That's still not quite as good as C, it really needs the notion of sequence points: https://en.wikipedia.org/wiki/Sequence_point
No comments yet.