-
Notifications
You must be signed in to change notification settings - Fork 29
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
Alternative reform #6
Comments
I don't think that's a bad option :) |
So: class (Functor f) <= Alt f where
(<|>) :: forall a. f a -> f a -> f a
class (Alt f) <= Plus f where
zero :: forall a. f a -> f a -> f a
class (Applicative f, Plus f) <= Alternative f Would we want to go with One thing I'm not sure about now is what happens with But it seems If there isn't a good reason for Basically, renaming |
Also pinging @joneshf / @puffnfresh / @jdegoes, any input would be appreciated again. |
Will review tomorrow if that's not too late. Sent from my iPhone
|
Do we have a use case in mind for breaking stuff up this way? |
Alright, here's another idea, excluding MonadOr as I don't think it needs to exist, however, if it does, all it would be is an empty class with In fact, do we need to even make it Perhaps with this |
Or |
I kind of want to turn this into a blog post, so it's going to get a bit wordy. Also, there wasn't a real good explanation for this in one specific place. As mentioned, I didn't really understand this whole thing before (and still feel a bit like I'm missing something), but I think the whole point of this branch in the hierarchy is to give monoidal semantics to functorial structures. We can't just use a fully qualified instance of This is what the So, to get the monoidal structure, we define similar classes.
As well, it should interact with the
And also interact with the
The interaction is
Interestingly, I'm not sure that we can say anything about left distributativity or left annihilation. See this answer for more details. Though, the conclusions reached may have only been in order to keep compatibility with what is already defined. Now, if we want to show that our monoidal semantics interact with the monadal structures, we need another type class for that. It would seem that we should have I feel that this is mostly a design decision. We have to say enough is enough, because otherwise we end up with an exponential explosion of typeclasses. So, maybe we don't really need to have both In any case, the laws that need to be held are
What I'm suggesting is that, if you have a This makes one ask, where does And that last part makes me ask, where is Thoughts? Most of this information was gathered from: http://stackoverflow.com/a/10168111/1549047 |
I'll check out those links and do some reading, but your reasoning seems pretty solid to me. I probably wasn't really approaching it from the right angle, one of the reasons I had Nice work. 👍 |
Well, it would be an empty definition for both classes, like how Also, your other formulations were good, don't discount them. Sometimes we need to take a second to think about how else we can express ideas, rather than just going with what has already been done. There's nothing suggesting that the Haskell way is the one right way. It's just the convention we have for most things, but we could've reformulated some of the types/classes and still gotten equivalent expressive power. I'd really like for there to be someway for us to specify at compile time the laws these are supposed to uphold, but without getting into full on proofs (which might be out of scope for the language), I'm not sure there's a way. I'd love to be wrong though. @jdegoes didn't you mention some kind of idea about verifying laws or something in #purescript like 3-4 months ago? |
I like @joneshf's proposal. I like the ones @garyb wrote down too, but I'm also in favour of removing as many intermediate classes as possible that we aren't likely to ever use (like I would be interested to try and find an example of a |
Type classes are only useful to the extent they have laws which permit formal reasoning. @joneshf This is far beyond the scope of this ticket, but in answer to your question, I would love it if type classes had a formal representation of their laws. In Idris, this is actually quite easy, although it becomes correspondingly harder to define instances. For a language like Purescript without dependent types, this would probably require special syntax / compiler support. I'm about 60% done with a blog post on type classes that explores some of the possibilities (unfortunately I started it months ago and haven't made any progress due to work!). |
There was an interesting Reddit post about how to use Template Haskell with QuickCheck to test laws as part of a type signature. I'd like to try something like that after ps-in-ps is working, as a library, as opposed to specific compiler support. |
I think we need
Our good friend ...
import qualified Data.Map as M
instance altMap :: (Ord k) => Alt (Map k) where
(<|>) m m' = m `M.union` m'
instance plusMap :: Plus (Map k) where
empty = M.empty
... But since you can't define an Then you might ask, do we need to be even more granular and have some interaction between
Looking forward to it! |
Thanks for the example :) |
I vote we go with @joneshf 's last suggestion. |
👍 If we were going to have a less confusing name for |
|
|
Possible confusion with monoidal functor anyway. Never mind. Probably best to just keep the names from semigroupoids. |
@paf31 What would this look like then, the way it is in semigroupoids?
The text was updated successfully, but these errors were encountered: