-
Notifications
You must be signed in to change notification settings - Fork 26
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
GOOL's buildClass should use module name for class name #2143
Comments
@bmaclach buildClass :: (RenderSym r) => Label -> Maybe Label -> [CSStateVar r] ->
[SMethod r] -> SClass r
buildClass n = S.intClass n public . inherit Question 1: What is the type of "public . inherit" from the build class function, is it r ParentSpec? class (BlockCommentSym r) => RenderClass r where
intClass :: Label -> r (Scope r) -> r ParentSpec -> [CSStateVar r]
-> [SMethod r] -> SClass r
inherit :: Maybe Label -> r ParentSpec
implements :: [Label] -> r ParentSpec
commentedClass :: CS (r (BlockComment r)) -> SClass r -> SClass r We need to get rid of the "Label" parameter and instead just use the string from getModuleName
Initial Solution buildClass = do
n <- getModuleName
S.intClass n public . inherit Which outputs the following error Question 2: I do not understand why I am getting this error. Obviously "n <- getModuleName" is an intermediate step, as it is the next line the returns the desired function, but why does haskell me to output the appropriate types in the first line. The second problem with this solution is that in Haskell at the end of a do statement you must return value wrapped in monad. So the last line should not work, because it would have type "[CSStateVar r] -> [SMethod r] -> SClass r" which is a function, not a monadic value. |
Question 1:
But, as you can see, using "point-free" style is cleaner. HLint will even suggest using point-free, where possible. Question 2: |
Questions for related to Haskell First question buildClass p stVars methods = do
n <- getModuleName
S.intClass n public (inherit p) stVars methods With buildClass returning type Sclass r , and getModuleName being of type State FileState String. This failed at line Is it because every monadic action inside of the do statement of build class must be of type “State ClassState r”, hence to execute a monadic action of type “State FileState String” we must first zoom into the FileState of the larger ClassState. This is why a function much as buildModule which is a FileState does not need a lens to set its name. buildModule n is ms cs= do
modify (setModuleName n) My second question is related to do statements and states in general. For example in the buildClass example, what state is the lens “lensCStoFS” lensing to, is it the initial file state? For example the _1 lens zooms into the state (1,2) in here |
Yes, exactly right. By calling
Hopefully this is making some sense. The |
BTW, it's always a good idea to put the words "closes # NNNN" in the PR text. When I merge it, it will automatically close the issue! |
@Nathaniel-Hu, please add to the Contributor's Guide (#2136) the advice from @JacquesCarette about automatically closing an issue with a PR. You can just add the advice to the wiki. There is no need for a local copy under version control. |
@Nathaniel-Hu Unrelated to your above, question, but I just noticed under "Merging Pull Requests", the "Dependent Changes" point is outdated. I think you should replace it with your 4th bullet point under "Creating Pull Requests". |
@bmaclach, I have merged the two points together as an entry under "Creating Pull Requests". Please review it for clarity/accuracy. Thanks! |
@Nathaniel-Hu The wording is good in my opinion, but I think you should link to this comment: #2157 (comment) either instead of or in addition to the comment you are already linking to. |
I agree with linking the comment mentioned by @bmaclach above. |
The GOOL function
buildClass
currently takes aLabel
parameter for the name of the class. However, this class name should always match the module/file name (because some languages, like Java, require this). Thus, theLabel
parameter should be removed and instead the module name can be read from the state (usinggetModuleName
) and used as the class name.This could be a good first issue for someone to get acquainted with GOOL.
The text was updated successfully, but these errors were encountered: