drsFreeRefs ld@(DRS _ c)  gd = free c
  where free :: [DRSCon] -> [DRSRef]
        free []              = []
        free (Rel _ d:cs)    = snd (partition (flip (`drsBoundRef` ld) gd) d) `union` free cs
        free (Neg d1:cs)     = drsFreeRefs d1 gd `union` free cs
        free (Imp d1 d2:cs)  = drsFreeRefs d1 gd `union` drsFreeRefs d2 gd `union` free cs
        free (Or d1 d2:cs)   = drsFreeRefs d1 gd `union` drsFreeRefs d2 gd `union` free cs
        free (Prop r d1:cs)  = snd (partition (flip (`drsBoundRef` ld) gd) [r]) `union` drsFreeRefs d1 gd `union` free cs
        free (Diamond d1:cs) = drsFreeRefs d1 gd `union` free cs
        free (Box d1:cs)     = drsFreeRefs d1 gd `union` free cs
drsFreeRefs ld@(DRS _ c)  gd = free c
  where free :: [DRSCon] -> [DRSRef]
        free []              = []
        free (Rel _ d:cs)    = snd (partition (flip (`drsBoundRef` ld) gd) d) `union` free cs
        free (Neg d1:cs)     = drsFreeRefs d1 gd `union` free cs
        free (Imp d1 d2:cs)  = drsFreeRefs d1 gd `union` drsFreeRefs d2 gd `union` free cs
        free (Or d1 d2:cs)   = drsFreeRefs d1 gd `union` drsFreeRefs d2 gd `union` free cs
        free (Prop r d1:cs)  = snd (partition (flip (`drsBoundRef` ld) gd) [r]) `union` drsFreeRefs d1 gd `union` free cs
        free (Diamond d1:cs) = drsFreeRefs d1 gd `union` free cs
        free (Box d1:cs)     = drsFreeRefs d1 gd `union` free cs
drsFreeRefs ld@(DRS _ c)  gd = free c
  where free :: [DRSCon] -> [DRSRef]
        free []              = []
        free (Rel _ d:cs)    = snd (partition (flip (`drsBoundRef` ld) gd) d) `union` free cs
        free (Neg d1:cs)     = drsFreeRefs d1 gd `union` free cs
        free (Imp d1 d2:cs)  = drsFreeRefs d1 gd `union` drsFreeRefs d2 gd `union` free cs
        free (Or d1 d2:cs)   = drsFreeRefs d1 gd `union` drsFreeRefs d2 gd `union` free cs
        free (Prop r d1:cs)  = snd (partition (flip (`drsBoundRef` ld) gd) [r]) `union` drsFreeRefs d1 gd `union` free cs
        free (Diamond d1:cs) = drsFreeRefs d1 gd `union` free cs
        free (Box d1:cs)     = drsFreeRefs d1 gd `union` free cs