Skip to content

Instantly share code, notes, and snippets.

@Blaisorblade
Last active December 18, 2015 03:18
Show Gist options
  • Save Blaisorblade/5716721 to your computer and use it in GitHub Desktop.
Save Blaisorblade/5716721 to your computer and use it in GitHub Desktop.
Why does this not work?
{-# 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