Revise class constructor/accessor representation#928
Conversation
Having them in the environment alone is not enough, as typeclass desugaring doesn't extend the environment, it only alters the AST.
There was a problem hiding this comment.
There's also this, which is annoying.
There was a problem hiding this comment.
Does this process need to loop until a fixed point? I'm guessing not.
There was a problem hiding this comment.
No it doesn't, it's just that desugaring typeclasses reintroduces more cases. I tried juggling the order but my attempts resulted in other problems.
There was a problem hiding this comment.
Can you desugar the new cases when you generate them?
There was a problem hiding this comment.
Yeah, perhaps - I barely remember what I was doing now. It's not too complicated though, I'm just not sure where the additional cases came from off the top of my head.
|
This only occurs for the |
|
This seems related to #862 What does the |
There was a problem hiding this comment.
Can just be lazy here: [0..] and then even move this out into a CAF at the top level to be reused.
bindArr :: forall r. Bind (Function r)
bindArr = Bind (\__unused -> applyArr) (\m -> \f -> \x -> f(m(x))(x)) |
|
I think it would help if it could be |
|
I can produce a type like |
|
No, sorry, it should be the skolemized type. |
|
Get the same exact error with that: |
|
Ok, I think we can save this by changing a case in |
|
Just pushed those tweaks, is that what you had in mind? |
|
That's a shame, I was hoping it was something I was doing wrong! Here's the problem with |
|
|
|
Ok this isn't |
|
Or not... I can make some progress by using I'm giving up for tonight. |
|
Compiling Prelude and purescript-index seem to now work fine. What's left to do? Fix the tests? |
|
"Fixing" it so |
|
I think I've discovered another bug in the typechecker actually, different from the first one: data Sequence t = Sequence (forall m a. (Monad m) => t (m a) -> m (t a))
sequence :: forall t. Sequence t -> (forall m a. (Monad m) => t (m a) -> m (t a))
sequence (Sequence s) = s
sequenceArraySeq :: forall m a. (Monad m) => Array (m a) -> m (Array a)
sequenceArraySeq [] = pure []
sequenceArraySeq (x:xs) = (:) <$> x <*> sequenceArraySeq xs
-- This is fine
sequenceArray :: Sequence []
sequenceArray = Sequence (sequenceArraySeq)
-- So is this:
sequenceArray' :: Sequence []
sequenceArray' = Sequence ((\val -> case val of
[] -> pure []
(x:xs) -> (:) <$> x <*> sequence sequenceArray' xs))
-- This is not:
sequenceArray'' :: Sequence []
sequenceArray'' = Sequence (sequenceArraySeq :: forall m a. (Monad m) => Array (m a) -> m (Array a))
-- Nor is this:
sequenceArray''' :: Sequence []
sequenceArray''' = Sequence ((\val -> case val of
[] -> pure []
(x:xs) -> (:) <$> x <*> sequence sequenceArray''' xs) :: forall m a. (Monad m) => Array (m a) -> m (Array a))So it seems to be when using explicit types with constraints when passing a value into a function (I tried a normal function as well as a constructor, and actually found another bug there I'll open an issue for, both failed with the same kind of error). The error raised in both cases is like this, and is the same error as occurs in |
|
So the situation now is:
|
Conflicts: src/Language/PureScript/Pretty/Values.hs src/Language/PureScript/TypeChecker/Types.hs
|
@paf31 instead of the half explanations I was giving in IRC earlier, here's where this is at. Apart from type checker issues this is basically done. Data constructors are now generated for classes, instances/dictionaries are values that use the constructors, and member accessors destructure the data type to extract the instance members. A class and instance like this: class Sequence t where
sequence :: forall m a. (Monad m) => t (m a) -> m (t a)
instance sequenceArray :: Sequence [] where
sequence [] = pure []
sequence (x:xs) = (:) <$> x <*> sequence xsWill be desugared as this: data Sequence t = Sequence (forall m a. (Monad m) => t (m a) -> m (t a))
sequence :: forall t. Sequence t -> (forall m a. (Monad m) => t (m a) -> m (t a))
sequence (Sequence s) = s
sequenceArray :: Sequence []
sequenceArray = Sequence ((\val -> case val of
[] -> pure []
(x:xs) -> (:) <$> x <*> sequence sequenceArray xs) :: forall m a. (Monad m) => [m a] -> m [a])The problem now is how to deal with the instances during type checking. The code currently has two problems - sequenceArray :: Sequence []
sequenceArray = Sequence ((\__dict_Monad_18 -> \__dict_Monad_19 \val -> case val of
[] -> pure []
(x:xs) -> (:) <$> x <*> sequence __dict_Monad_19 xs) :: forall m a. (Monad m) => [m a] -> m [a])(We only want the If we try and use The fix I applied in master to resolve the constrained type argument only works when we're using I think that covers it! |
|
Stumbled on this and curious if it was abandoned? |
|
It's not, I just haven't returned to it yet, other things have seemed more pressing! |
This is almost working, but not quite. All that nonsense about special cases for class constructors, class constructor applications, member accessors is gone in favour of representing classes as standard data constructors... however, now I get a type error when trying to compile the prelude:
I could use a hand trying to figure out what's going wrong here, I've experimented a bit compiling something with
no-preludethinking it might be to do with higher kinded classes, but aFunctorclass and instance certainly works ok.Will close #781 when finished.