-
Notifications
You must be signed in to change notification settings - Fork 375
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
Add Monad instance for Prelude.id #3086
Conversation
It would be nice if you could add some documentation about when to use this and when |
The manual says:
but this immediately creates overlapping definitions with every single implementation: So I don't think this should get in. |
As an example, consider defining mapState : ((s, a) -> (s, b)) -> State s a -> State s b
mapState f = mapStateT $ \(Id p) => Id (f p) Note that we wrap/unwrap the If we were to use mapState : ((s, a) -> (s, b)) -> State s a -> State s b
mapState = mapStateT {m = id} {n = id} Indeed, The only cases were you couldn't would be when Idris needs to use the type of the function to determine the monad for That said, we shouldn't change any of the existing transformers, for backwards compatibility. With regards to overlapping definitions, I don't think Idris will detect any overlap, as an applied That said, I can certainly understand the problem from a purity perspective. Would you prefer they be named implementations? |
At first, I also thought that claims of overlapping definitions are viable. But then I realised that it does not seem right. I experimented with it shortly, and quick look indeed does not show any detected overlap: interface X (0 m : Type -> Type) where
h : m a -> m a
X List where
h = id
X Prelude.id where
h = id
f : List a -> List a
f = h
f' : a -> a
f' = h {m=id} But what I can see here that Additionally, I thought if inability to find such an implementation is related to #2522 |
The benefit comes when using transformers. To extend your example, consider types record YT (m : Type -> Type) (a : Type) where
constructor MkYT
y : m a
Y : Type -> Type
Y = YT id
g : X m => m a -> YT m a
g y = MkYT $ h y
g' : a -> Y a
g' = g In the last line, the |
I'll just close this as it goes against the explicitly stated intentions behind interfaces. |
While
Identity
is better for most cases, you can occasionally get away withid
instead. This has the benefit of not needing to wrap/unwrap your result.