Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Is it possible to force a type to a class in Haskell?
- module T where
- import Debug.Trace
- dosum :: (Num a) => [a] -> a
- dosum xs = dosum' 0 xs
- where
- dosum' n [] = n
- dosum' n (x:xs) = trace (show n) $ dosum' (n+x) xs
- Could not deduce (Show a) arising from a use of dosum'
- from the context (Num a)
- unsafeShow :: a -> String
- class (Num a) => Number a
- instance (Num a) => Number a
- -- original function, should add NOINLINE to make sure your rule gets a chance to fire.
- {-# NOINLINE dosum #-}
- dosum :: (Num a) => [a] -> a
- -- a version with added debugging
- dosumShow :: (Num a, Show a) => [a] -> a
- {-# RULES "sub/dosum" forall x. dosum x = dosumShow x #-}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement