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

WIP: tree shaking of type class instances #5

Closed
wants to merge 25 commits into from
Closed

Conversation

coot
Copy link
Collaborator

@coot coot commented Sep 1, 2017

No description provided.

@coot
Copy link
Collaborator Author

coot commented Sep 1, 2017

#4 needs to be resolved before merging this issue

Marcin Szamotulski added 4 commits September 1, 2017 23:02
* bindIdents	- get all identifier of a bind
* unApp	      	- get abstraction and arguments of a recursive `App`
* isShadowed  	- check if a qualified ident is shadowed by an identifier
* identFromVal	- get qualified identifier from a `Var` expression
@coot
Copy link
Collaborator Author

coot commented Sep 2, 2017

gn :: forall a. Show a => a -> Maybe String
gn a =
  -- no type annotation is present for gnRes in CoreFn for `gnRes`
  let gnRes = fn a
  in gnRes

Then the CoreFn gnRes is:

gnRes
  App
    (App
      (App
        (Var Let.fn :type ForAll m (ForALl a (ConstrainedType Data.Show.Show (ConstrainedType Control.Monad.Monad ...))))
        (Var dictShow))
      (Data.Maybe.monadMaybe))
    (Var a)

PureScript compiler places the resolved type class constrain inside the call to fn :: forall a m :: Show a=> Monad m => a -> m String. The same happens when gn looks like

gn' :: forall a. Show a => a -> Maybe String
gn' a =
  -- no type annotation is present in CoreFn for `coercedFn`
  let coercedFn x = fn x
  in coercedFn a

It seems that this is the rule that PureScript fills constraints, rather than creating constraint types for coercedFn that resolves type class instances when calling coercedFn a. But one can force this with type annotations:

gn'' :: forall a. Show a => a -> Maybe String
gn'' a =
  let 
      -- the type signature is reflected in CoreFn annotation
      coercedFn :: forall m. Monad m => a -> m String
      coercedFn x = fn x
  in coercedFn a

Marcin Szamotulski added 6 commits September 9, 2017 00:52
* It needs to return the final argument (`dictShow` or
`Data.Show.showInt`)
* simplify and review it's logic
@coot coot force-pushed the master branch 2 times, most recently from 8904ed4 to b1d1265 Compare May 23, 2018 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant