Created
August 22, 2021 22:01
-
-
Save noteed/ef1867d4ca4ec3f04233f7d57777f183 to your computer and use it in GitHub Desktop.
Capabilities ?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data V4 = V4 deriving Show | |
data V6 = V6 deriving Show | |
class V4Getter getter where getIPV4 :: getter -> IO V4 | |
class V6Getter getter where getIPV6 :: getter -> IO V6 | |
class (V4Getter getter, V6Getter getter) => V4V6Getter getter | |
data Svc1 = Svc1 | |
instance V4Getter Svc1 where getIPV4 _ = return V4 | |
data Svc2 = Svc2 | |
instance V6Getter Svc2 where getIPV6 _ = return V6 | |
data Svc3 = Svc3 | |
instance V4Getter Svc3 where getIPV4 _ = return V4 | |
instance V6Getter Svc3 where getIPV6 _ = return V6 | |
instance V4V6Getter Svc3 | |
f1 :: V4V6Getter getter => getter -> IO (V4, V6) | |
f1 getter = do | |
v4 <- getIPV4 getter | |
v6 <- getIPV6 getter | |
return (v4, v6) | |
f2 :: Svc3 -> IO (V4, V6) | |
f2 getter = do | |
v4 <- getIPV4 getter | |
v6 <- getIPV6 getter | |
return (v4, v6) | |
{- | |
-- error: Could not deduce (V6Getter getter) | |
g1 :: V4Getter getter => getter -> IO (V4, V6) | |
g1 getter = do | |
v4 <- getIPV4 getter | |
v6 <- getIPV6 getter | |
return (v4, v6) | |
-} | |
{- | |
-- error: No instance for (V4Getter Svc2) arising from a use of ‘getIPV4’ | |
g2 :: Svc2 -> IO (V4, V6) | |
g2 getter = do | |
v4 <- getIPV4 getter | |
v6 <- getIPV6 getter | |
return (v4, v6) | |
-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment