[GHC] #11113: Type family If is too strict

GHC ghc-devs at haskell.org
Thu Nov 19 14:48:06 UTC 2015


#11113: Type family If is too strict
-------------------------------------+-------------------------------------
           Reporter:  olshanskydr    |             Owner:
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  7.10.2
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 This code
 {{{#!hs
 type family Div (k::Nat) (n::Nat) where
     Div k n = If (CmpNat k n == LT) 0 (1 + Div (k-n) n)
 }}}
 is not working. When I try
 {{{
 ghci> :t (Proxy :: Proxy (Div 100 9))
 }}}
 it hangs on. Probably ghci is trying to calculate both '''If''' branches.

 If I rewrite it this way
 {{{#!hs
 type family Div (k::Nat) (n::Nat) where
     Div k n = Div' k n (CmpNat k n)

 type family Div' (k::Nat) (n::Nat) (b::Ordering) where
     Div' k n LT = 0
     Div' k n EQ = 1
     Div' k n GT = 1 + Div (k-n) n
 }}}
 it works well

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11113>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list