tomjaguarpaw / strict-wrapper

MIT License
17 stars 0 forks source link

Ergonomics #2

Open eddiemundo opened 5 months ago

eddiemundo commented 5 months ago

Hi, thanks for this library.

I was trying out the library and it seems to me that one advantage having parallel strict types has over wrapping with Strict is I can use fmap on the strict types directly. If somebody likes the style of using maybe or fmap then fromMaybe instead of pattern-matching it feels a lot more awkward having to pattern match, then do those, then re-Strict afterwards.

Another thing that doesn't come out of the box are instances like Show and Eq which makes me want to create orphan instances.

It is nice that you can use the tuple syntax for strict tuples though.

Anyway those are my superficial thoughts.

eddiemundo commented 5 months ago

I have no idea why I posted this since it's not a question, and offers no solutions.

The ergonomics of the strict package feels a little better but also doesn't yet have Applicative or Monad instances out of the box for types Maybe, Either. But one can more or less create a strict prelude with those although have to call toStrict, toLazy a lot to work with the rest of the ecosystem.

tomjaguarpaw commented 5 months ago

It's a good thought. Let's keep it open. I am very interested to improve the ergonomic experience of this library.

tomjaguarpaw commented 5 months ago

Regarding fmap, I can add mapStrict that will let you use mapStrict . fmap

mapStrict :: (Strictly a, Strictly b) => (a -> b) -> Strict a -> Strict b
mapStrict f = strict . f . unstrict

Regarding maybe or fromMaybe, anyone can write versions that work on Strict (Just a). That doesn't need to be done internally to the library.

About instances, you're right. I can add them. Which would you like to be added? Eq, Ord, Show?

It won't work with Applicative and Monad because they have the wrong kind. I could change Strict from a data family to a type family to deal with that, but that would be a breaking change I guess.

See this commit for mapStrict and the instances. What do you think? https://github.com/tomjaguarpaw/strict-wrapper/commit/6f40e7ddf4ab22aceb945b4f807e9c30ce98a0d9

tomjaguarpaw commented 4 months ago

I added Eq, Ord, Show and Read instances in https://github.com/tomjaguarpaw/strict-wrapper/commit/ac0af50c1f1e78a85f44bcb871d7c8ed46b3bf04 and released as https://hackage.haskell.org/package/strict-wrapper-0.0.1.0