How to create Haskell containers that merge?

I'm interested in creating a new type of Haskell container (strict lists), and I want to make sure that operations with them have the right to merge threads. How can I refuse the possibility of merging ghc streams?

If my container is Traversable , will it work automatically? If I implemented, say, mapAccumL in terms of toList , would Haskell be smart enough not to convert the container to a list at all, but just work on the base view?

+5
source share
1 answer

GHC is not really intelligent. It is just (good) software. If you want your new thing to merge, you have several options:

  • Build it on top of what’s already working: fuse lists using foldr/build merge, and vector transporters using thread merge. If you build your type on top of one of them, you will probably be able to arrange its proper connection without any problems. If you have this option, this is by far your best bet.

  • Fuse only on interfaces: even if your type does not merge, you can organize a certain amount of merging when it is converted to a list from or from a list or from it.

  • Collect the merge rules yourself: this is not too difficult in principle, but in practice you will bang your head on the wall, so if you are not as crazy as I can, you can avoid this approach: the rules will not work when you want, they will to intervene in complex ways with other rules, Inliner will make you its &% $ # @, and even when everything works correctly, the tests will show the opposite of what you want.

+9
source

Source: https://habr.com/ru/post/1208205/


All Articles