Safe Haskell | None |
---|
PartialTypeSigs
Description
Example usage (GHC-7.8):
sigs [| ["f1" :: a -> b -> (a, Int), "f1" :: b -> a -> (Char, a) ] |] f1 x y | False = $(unionSigs [| f1 x y |]) f1 x y = undefined -- (x,y)
A GHC-7.6 compatible version must be slightly longer to work around the extra typechecking done of [| |] brackets:
sigs [| do f2 <- Nothing Just [ f2 :: a -> b -> (a, Int), f2 :: b -> a -> (Char, a) ] |] f2 x y | False = $(unionSigs [| f2 x y |]) f2 x y = undefined -- (x,y)
If the expression splice generated by unionSigs
is left out,
sigs [| ["g" :: a -> b -> (a, Int), "g" :: b -> a -> (Char, a) ] |] g x y = undefined -- (x,y)
then g
's type takes the most general type (g :: t)
, and the two
functions defined by sigs
can be used to restrict the type of g:
partialTypeSig_g1 :: (t -> t1 -> (t, Int)) -> t -> t1 -> (t, Int) partialTypeSig_g1 = id partialTypeSig_g2 :: (t -> t1 -> (Char, t1)) -> t -> t1 -> (Char, t1) partialTypeSig_g2 = id
Documentation
any subexpression of the passed-in expression which looks like:
"functionName" :: t functionName :: t
generates the following function:
partialTypeSig_functionName1 x = x `asTypeOf` (functionName `asTypeOf` (undefined :: t))
Note that the above function is not the same as
badId x = x `asTypeOf` (functionName :: t)
which requires that t
be more specific than functionName