Created
November 11, 2016 02:44
-
-
Save goldfirere/a8c52c81e70407af7fd2b50f73ba34a1 to your computer and use it in GitHub Desktop.
Inferring constraints with polymorphic recursion
This file contains 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
module EvalPolyRec where | |
import Prelude hiding (seq) | |
class Eval a where | |
seq :: a -> b -> b | |
instance Eval (a,b) where | |
seq (_, _) = id | |
data SP a b = SP !a !b | |
instance (Eval a, Eval b) => Eval (SP a b) where | |
seq (SP a b) = a `seq` b `seq` id | |
szip :: [a] -> [b] -> [SP a b] | |
szip (a : as) (b : bs) = SP a b : szip as bs | |
szip _ _ = [] | |
f :: Eval a => [a] -> () | |
f [] = () | |
f (x : xs) = x `seq` f (zip xs xs) | |
g :: Eval a => [a] -> () | |
g [] = () | |
g (x : xs) = x `seq` f (szip xs xs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not a commentary on the code, I'm just bored
Should that last
f
be ag
?