{-# LANGUAGE ConstraintKinds #-}{-# LANGUAGE DataKinds #-}{-# LANGUAGE GADTs #-}{-# LANGUAGE TypeFamilies #-}typefamilyB(b::Bool)typeinstanceBTrue=()typeinstanceBFalse=()dataDictcwhereDict::c=>DictcdataSBool(b::Bool)whereSTrue::SBoolTrueSFalse::SBoolFalsebla::SBoolb->Dict(Show(Bb))blaSTrue=DictblaSFalse=Dictf::SBoolb->Bb->Stringfsbbb=doDict<-pure$blasbshowbb
is there some "cleaner" way to introduce constraints, than to do with* style functions, that increase indentation levels (depending on your formatting style)
:joy: - I was confused too, so I plugged it into -ddump-ds and of course, GHC.Base.$fMonad[] appeared :big_smile:
btw if you're running hls, you can ask for the type of pure above and it will also show you the concrete type being used at that point, not only the generic type it has
at this point I'm just sticking all of them in a single type Shows ty = <list all the Shows I need> and having a hasShow :: Sing ty -> (Shows ty => r) -> r
Quick question: I’ve been reading through this thread, and there’s a couple of references to GHC.Base.$fMonad[] as an explanation for how this works. As someone who is unfamiliar with the internals of GHC, what does GHC.Base.$fMonad[] do and why is it relevant here?
Instances are then represented simply as values of this datatype - or functions, if they take some constraints
Finally, $fMonad[] is simply some generated name given to one such instance (Monad [])
It isn't really about typeclass desugaring in this case - I just dumped desugared internal representation of Haskell, because I wanted to see what do turns into :smile:
Yeah - compared to OOP languages, Haskell basically decouples vtables into separate entities (constraints), instead of packing them together with defined datatype
Ok so
this is fine, and looks pretty normal to me
but also...
this works
what does the
pure "haha"
+ the bind desugar to??I can tell for sure that it's not ignored, because..
this works!
so I guess it has to be some case statement??
in any case, very weird that they decided to do that.. I think?
but it might just be useful for my use case now :smiling_imp:
or are these the evil machinations of some weird
Monad
instance? (like(r->)
)omg... it's
[]
:face_palm:
:joy: - I was confused too, so I plugged it into
-ddump-ds
and of course,GHC.Base.$fMonad[]
appeared :big_smile:argh!!!!
stupid string
Easy to forget for sure :big_smile:
bye bye easy introduction of Dicts :sob:
is there some "cleaner" way to introduce constraints, than to do
with*
style functions, that increase indentation levels (depending on your formatting style)or in general is there some cleaner way to handle producing constraints for instances for type families? :(
TheMatten said:
btw if you're running hls, you can ask for the type of
pure
above and it will also show you the concrete type being used at that point, not only the generic type it hasextremely useful!
Just do
:big_smile:
yes, that was my next step
but I'm not on a ghc supporting it yet
lovely how many good things come out of just
QualifiedDo
It's how all sugar should work IMHO :smile:
yup, exactly
at this point I'm just sticking all of them in a single
type Shows ty = <list all the Shows I need>
and having ahasShow :: Sing ty -> (Shows ty => r) -> r
but this doesn't scale well when not all your datatypes are in one place
I guess the ""solution"" to this is to create a unifying module for all of them which only has
Shows
andhasShow
in itI wonder how much this makes ghc slower
it also doesn't scale well if you have more
ty
sQuick question: I’ve been reading through this thread, and there’s a couple of references to
GHC.Base.$fMonad[]
as an explanation for how this works. As someone who is unfamiliar with the internals of GHC, what doesGHC.Base.$fMonad[]
do and why is it relevant here?I think that's the internal name for the dict for the Monad instance for
[]
do you know how type classes are handled in core?
@bradrn
GHC translates classes into what are basically record types - so
translates into something equivalent to
Instances are then represented simply as values of this datatype - or functions, if they take some constraints
Finally,
$fMonad[]
is simply some generated name given to one such instance (Monad []
)It isn't really about typeclass desugaring in this case - I just dumped desugared internal representation of Haskell, because I wanted to see what
do
turns into :smile:I think it has almost the same role as a vtable
Yeah - compared to OOP languages, Haskell basically decouples vtables into separate entities (constraints), instead of packing them together with defined datatype
Ah, of course! So that
do
block just ends up using theMonad []
instance. Thanks @Georgi Lyubenov // googleson78 @TheMatten!