[Haskell-cafe] Manual constructor specialization

Roberto Zunino zunino at di.unipi.it
Tue Oct 9 15:11:21 EDT 2007


A GADT version seems to generate OK code:

data Top
data NTop
data Rope t where
 Empty :: Rope Top
 Leaf :: Rope NTop
 Node :: !(Rope NTop) -> !(Rope NTop) -> Rope NTop

index :: Rope t -> Int -> Word8
index Empty _      = error "empty"
index Leaf _       = error "leaf"
index (Node l r) n = index' l n
    where
      index' :: Rope NTop -> Int -> Word8
      index' Leaf _       = error "leaf"
      index' (Node l r) n = index' l n

Here's the result of -O -ddump-simpl for index':

$windex'_rx5 =
  \ (w_swu :: Tree.Rope Tree.NTop) ->
    case w_swu of wild_Xf {
      Tree.Leaf -> lvl1_rwZ; Tree.Node l_adF r_adG -> $windex'_rx5 l_adF
    }

Regards,
Zun.


More information about the Haskell-Cafe mailing list