Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ergonomics #2

Open
eddiemundo opened this issue May 5, 2024 · 4 comments
Open

Ergonomics #2

eddiemundo opened this issue May 5, 2024 · 4 comments

Comments

@eddiemundo
Copy link

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
Copy link
Author

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
Copy link
Owner

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

@tomjaguarpaw tomjaguarpaw reopened this May 5, 2024
tomjaguarpaw added a commit that referenced this issue May 5, 2024
tomjaguarpaw added a commit that referenced this issue May 5, 2024
@tomjaguarpaw
Copy link
Owner

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? 6f40e7d

@tomjaguarpaw
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants