Skip to content

Instantly share code, notes, and snippets.

@phadej
Created October 17, 2020 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phadej/7b95d1876dd085d28f49bf4ebf349663 to your computer and use it in GitHub Desktop.
Save phadej/7b95d1876dd085d28f49bf4ebf349663 to your computer and use it in GitHub Desktop.
class MyNum a where
my_plus :: a -> a -> a
my_fromInteger :: Integer -> a
class MyNum a => MyIntegral a where
my_toInteger :: a -> Integer
my_fromIntegral :: (MyIntegral a, MyNum b) => a -> b
my_fromIntegral = my_fromInteger . my_toInteger
-- this is silly
plus :: (MyIntegral a, MyIntegral b) => a -> b -> a
plus a b = my_plus a (my_fromIntegral b)
plus2 a b = plus b (plus b a) -- reverse
result = plus2 1 2
{-
• No instance for (MyIntegral b1) arising from a use of ‘plus2’
• In the expression: plus2 1 2
In an equation for ‘result’: result = plus2 1 2
|
30 | result = plus2 1 2
| ^^^^^^^^^
bar.hs:30:16: error:
• Ambiguous type variable ‘b0’ arising from the literal ‘1’
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment