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

#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

#11113: Type family If is too strict -------------------------------------+------------------------------------- Reporter: olshanskydr | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Description changed by olshanskydr: Old description:
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
New description: 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. This code also not working {{{#!hs type family Div (k::Nat) (n::Nat) where Div k n = Div'' k n (CmpNat k n == LT) type family Div'' (k::Nat) (n::Nat) (b::Bool) where Div'' k n b = If b 0 (1 + Div (k-n) n) }}} -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11113#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11113: Type family If is too strict -------------------------------------+------------------------------------- Reporter: olshanskydr | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by goldfire): At one point, I thought I could come up with a terrible hack that would fix this, but I don't think so anymore. What we really need is a proper (preferably lazy!) semantics for type-level reduction. I'm afraid I can't offer any workaround better than the one you've already come up with. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11113#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11113: Type family If is too strict -------------------------------------+------------------------------------- Reporter: olshanskydr | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Resolution: | Keywords: TypeFamilies Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by enolan): * cc: echo@… (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11113#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC