-
Notifications
You must be signed in to change notification settings - Fork 564
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
Check exports #640
Check exports #640
Conversation
decls' <- typeCheckAll mainModuleName mn exps decls | ||
forM_ exps checkTypesAreExported | ||
forM_ exps checkClassMembersAreExported | ||
forM_ exps checkClassesAreExported |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm being incredibly dense, but couldn't work out a better way of doing this... suggestions please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I'm missing something, but what's wrong with this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forM_ exps ...
3 times seemed a little silly. If it's fine though, that's great, it'd explain why I couldn't think of a way to avoid it! (I tried using >>
to compose the checks at first, but then errors get lost, etc.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, you could do
forM_ exps $ \e -> do
checkTypesAreExported e
checkClassMembersAreExported e
checkClassesAreExported e
I don't think that's too bad. Lambdabot kindly offers the following:
forM_ exps $ flip mapM
[ checkTypesAreExported
, checkClassMembersAreExported
, checkClassesAreExported
] . flip id
which seems much worse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, yeah. First one looks good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
forM_ exps check
[ typesAreExported
, classMembersAreExported
, classesAreExported
]
where
check :: (Monad m) => [a -> m b] -> a -> m ()
check fs = flip mapM_ fs . flip id
I think that's the maximally acceptable amount of golfing.
Just went with the most basic option in the end... ok to merge when you're happy with the rest of it. :) |
The code looks good, but I don't understand why we're doing this to be honest. Why should a class export force members to be exported? Maybe I want the exact opposite, because I'm exposing "smart members". Edit: certainly the converse should be required, or the type signatures wouldn't make sense. Edit: basically, I'm saying that I think |
Wouldn't partially exporting a class prevent it from ever having new instances added? |
Yes, that's true. Is that a bad thing? (genuine question) |
If it can't have new instances, why does it need to be a type class? It can be hidden entirely inside the module, right? |
I suppose that's true. But in that case, the exports section is unnecessarily verbose. The members should just be exported whenever the type class is. |
This is fine though. I say we merge this, and consider a less verbose syntax for type class exports later. |
I originally asked for this feature due to the number of times I export a class but fail to export its methods. It compiles clean, all tests pass, and no one can use the damn thing! It'd be nice if, like Haskell, we supported |
Agreed, it would be nice to have the same syntax as Haskell. In imports too, obviously. Edit: actually, I still think it makes sense to just import everything for a type class together, just by importing the type class name. |
Maybe that's the way to go then, and we can remove this check again later. At the moment we have a slight syntactic difficulty with using |
My vote would be for |
@garyb Thanks for fixing this! |
No problem. 🍰 |
Closing #562 again, and also checks that when a class is exported so are all its members, as suggested by @jdegoes.