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
Write default implementation to getLogAction via logActionL #123
Comments
@chshersh Is this something I can work on if my understanding is correct? I see logActionL is a Lens. If I understand correctly, the get and set you mention refer to the getter and setter in the context of Lens? Depending on what operation I apply using logActionL, I can retrieve getLogAction and setLogAction from logActionL. Am I thinking correctly here? But, then the class seems to do just this and I was looking first at the instances. Can you clarify a bit more. This is my first time looking at Has pattern. |
@SanchayanMaity The Since lens has getter and setter capabilities, it should be enough to define only So, in simple words, this issue is about the following:
|
@chshersh Does this look good? Edit: Diff updated diff --git a/co-log-core/src/Colog/Core/Class.hs b/co-log-core/src/Colog/Core/Class.hs
index d2f6c92..8aa2d8d 100644
--- a/co-log-core/src/Colog/Core/Class.hs
+++ b/co-log-core/src/Colog/Core/Class.hs
@@ -19,7 +19,7 @@ module Colog.Core.Class
) where
import Colog.Core.Action (LogAction)
-
+import Data.Functor.Const (Const, getConst)
-- to inline lens better
{- HLINT ignore "Redundant lambda" -}
@@ -37,10 +37,12 @@ Every instance of the this typeclass should satisfy the following laws:
4. __Set-Over:__ @'overLogAction' f env ≡ 'setLogAction' (f $ 'getLogAction' env) env@
-}
class HasLog env msg m where
- {-# MINIMAL getLogAction, (setLogAction | overLogAction) #-}
+ {-# MINIMAL (getLogAction | logActionL) , (setLogAction | overLogAction) #-}
-- | Extracts 'LogAction' from the environment.
getLogAction :: env -> LogAction m msg
+ getLogAction = getConst . logActionL Const
+ {-# INLINE getLogAction #-}
-- | Sets 'LogAction' to the given one inside the environment.
setLogAction :: LogAction m msg -> env -> env |
@SanchayanMaity A few notes:
|
@chshersh Thank you for your patience & sorry for asking stupid questions.
If I do an import with explicit lists as below which is what I was trying to do import Data.Functor.Const (Const, getConst) I get an error, which I do not expect
Either someone provides logActionL and we retrieve getLogAction from that or they provide getLogAction. Ditto for the other one. So below? {-# MINIMAL (getLogAction | logActionL) , (setLogAction | overLogAction) #-} |
@SanchayanMaity you need to import constructor of the import Data.Const (Const (..))
Below doesn't look correct either. |
Closed in #153 |
So it will be enough to implement either
logActionL
orget + set
.The text was updated successfully, but these errors were encountered: