Hi guys! I want to write an Enum instance for tuples and I want to have a faster version if the second component of the tuple is an Int how do I do that? I searched the specialize pragma, but didn't understand how to use it
I've added the following rewrite rule to conduit without issue:
{-# RULES "ConduitM: lift x >>= f" forall m f.
lift m >>= f = ConduitM (PipeM (liftM (unConduitM . f) m))
#-}
I'm
I've added the following rewrite rule to conduit without issue:
{-# RULES "ConduitM: lift x >>= f" forall m f.
lift m >>= f = ConduitM (PipeM (liftM (unConduitM . f) m))
#-}
I'm
@Bolt giving errors is not very helpful without the code that caused the error in the first place. food for thought in the future when asking questions
GHC can definitely internally create rules of the form you're asking about, but i'm not sure the language exposed to source haskell is powerful enough to bind dictionaries
Hi guys! I want to write an
Enum
instance for tuples and I want to have a faster version if the second component of the tuple is anInt
how do I do that? I searched the specialize pragma, but didn't understand how to use itand how does it work
I have this and I want to use
toEnumInt
in the specialized versionIs it specialized or rewrite rule pragma that I want?
Is it specialized or rewrite rule pragma that I want?
I think if you want to write the function yourself, you want a rewrite rule
The specialize pragma just generates a specialized version of the function along with a rewrite rule to use the generated specialized version
I am trying with rewrite rule but I get this error
What's your rule look like?
Oh, actually, you probably just have to stick an
Enum a
on itHow?
@Bolt Example: https://stackoverflow.com/a/25326480
Oh, although it may not actually fire because Core is silly. Maybe you need
ifcxt
like in https://stackoverflow.com/a/25326480I guess try the first way and use
-ddump-rule-firings
to see if it actually works, then go down the other route if not@Bolt giving errors is not very helpful without the code that caused the error in the first place. food for thought in the future when asking questions
this thing is not a
SPECIALIZE
--- that just tells GHC to optimize a definition with a specific type signaturei would further describe this as "don't put in the effort"
rewrite rules are tricky to get right and often lead to pain
instead what you really want to do is give an
OVERLAPPING
instance ofEnum a => Enum (a, Int)
GHC can definitely internally create rules of the form you're asking about, but i'm not sure the language exposed to source haskell is powerful enough to bind dictionaries
http://reasonablypolymorphic.com/blog/specialization/#rewrite-rules i wrote a thing on grokking rewrite rules if you're interested
I will keep that in mind!
Nice @Sandy Maguire ! Your suggestion worked! Haskell can have weird things, thanks for the help!