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

Check exports #640

Merged
merged 4 commits into from
Oct 16, 2014
Merged

Check exports #640

merged 4 commits into from
Oct 16, 2014

Conversation

garyb
Copy link
Member

@garyb garyb commented Oct 16, 2014

Closing #562 again, and also checks that when a class is exported so are all its members, as suggested by @jdegoes.

decls' <- typeCheckAll mainModuleName mn exps decls
forM_ exps checkTypesAreExported
forM_ exps checkClassMembersAreExported
forM_ exps checkClassesAreExported
Copy link
Member Author

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?

Copy link
Contributor

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?

Copy link
Member Author

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.)

Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.0%) when pulling 9f4cb6f on check-exports into 5a20c09 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.0%) when pulling 4350be8 on check-exports into 5a20c09 on master.

@garyb
Copy link
Member Author

garyb commented Oct 16, 2014

Just went with the most basic option in the end... ok to merge when you're happy with the rest of it. :)

@paf31
Copy link
Contributor

paf31 commented Oct 16, 2014

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 checkClassMembersAreExported is too strong a condition.

@garyb
Copy link
Member Author

garyb commented Oct 16, 2014

Wouldn't partially exporting a class prevent it from ever having new instances added?

@paf31
Copy link
Contributor

paf31 commented Oct 16, 2014

Yes, that's true. Is that a bad thing? (genuine question)

@jdegoes
Copy link

jdegoes commented Oct 16, 2014

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?

@paf31
Copy link
Contributor

paf31 commented Oct 16, 2014

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.

@paf31
Copy link
Contributor

paf31 commented Oct 16, 2014

This is fine though. I say we merge this, and consider a less verbose syntax for type class exports later.

paf31 added a commit that referenced this pull request Oct 16, 2014
@paf31 paf31 merged commit 3634a8d into master Oct 16, 2014
@paf31 paf31 deleted the check-exports branch October 16, 2014 14:25
@jdegoes
Copy link

jdegoes commented Oct 16, 2014

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 Foo(..) for type classes so you could export all members automatically. I think I did that a few times before downgrading to Foo once I got a compilation error.

@paf31
Copy link
Contributor

paf31 commented Oct 16, 2014

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.

@garyb
Copy link
Member Author

garyb commented Oct 16, 2014

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 T(..) and C(..), but will just have to add a step in Names or something to lookup whether things are types or classes and remove the ambiguity there.

@paf31
Copy link
Contributor

paf31 commented Oct 16, 2014

My vote would be for import T, which would import a type class and all its members. Importing a class and only some members is disallowed, so should be syntactically invalid.

@paf31
Copy link
Contributor

paf31 commented Oct 16, 2014

@garyb Thanks for fixing this!

@garyb
Copy link
Member Author

garyb commented Oct 16, 2014

No problem. 🍰

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

Successfully merging this pull request may close these issues.

None yet

4 participants