Last active
December 18, 2015 03:18
-
-
Save Blaisorblade/5716721 to your computer and use it in GitHub Desktop.
Why does this not work?
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
{-# LANGUAGE TypeFamilies #-} | |
module DeltaInt where | |
class Changing a where | |
-- Using type families here is a bit convenient, but means risking trouble later. | |
type Delta a | |
nil :: a -> Delta a | |
apply :: a -> Delta a -> a | |
diff :: a -> a -> Delta a | |
instance Changing Integer where | |
type Delta Integer = Integer | |
nil = const 0 | |
apply = (+) | |
diff = (-) | |
-- Fails: | |
v :: Delta Integer | |
v = diff 2 1 | |
{- Error: | |
DeltaInt.hs:21:5: | |
Couldn't match type `Delta a0' with `Integer' | |
Expected type: Delta Integer | |
Actual type: Delta a0 | |
In the return type of a call of `diff' | |
In the expression: diff 2 1 | |
In an equation for `v': v = diff 2 1 | |
Failed, modules loaded: none. | |
-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment