haskell-nix / hnix

A Haskell re-implementation of the Nix expression language
https://hackage.haskell.org/package/hnix
BSD 3-Clause "New" or "Revised" License
768 stars 115 forks source link

Please, promote NValue to newtype #1008

Closed Anton-Latukha closed 3 years ago

Anton-Latukha commented 3 years ago

Currently NValue is:

type NValue t f m = Free (NValue' t f m) t

And type signatures sometimes span kilometers.

newtypeing it is a big change through the project. But better to do it sooner than later.

Typing sometimes is so complex, & because of no proper type distinction - even GHC inference has problems of matching variations of Free (NValue' t f m) t with NValue t f m - what to say about people. newtypeing it would make the type system approachable for newcomers. % should help implementations of additional complex functionality.

Main type of the project currently does not have instances - it uses Free & NValue' instances.

Person arrives - and besides being confused with recursion schemes & NValueF, NValue', NValue - does not see what classes the main type of the project supports.

Properly abstracting the type would also ease the further work with it.

Anton-Latukha commented 3 years ago

Tried this yesterday.

It can't be done. GHC does not allow it. At least with my level of understanding.

Seems that it is easier to do other stuff & in the end replace Free monad to proper Monad.