[GHC] #12048: Allow CustomTypeErrors in type synonyms (+ evaluate nested type family?)

#12048: Allow CustomTypeErrors in type synonyms (+ evaluate nested type family?) -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: Type: feature | Status: new request | Priority: normal | Milestone: Component: Compiler | Version: 8.1 Keywords: | Operating System: Unknown/Multiple CustomTypeErrors | Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- I didn't find a ticket with this, but with wiki:CustomTypeErrors you can't define a type synonym without it erroring: {{{#!hs -- error: … -- • onetwothree -- • In the type synonym declaration for ‘ERROR’ -- Compilation failed. type ERROR = TypeError (Text "onetwothree") }}} but I often want to abstract over error messages since they are clunky to write at the type level and I often use a similar message in many different type families, especially when they can be determined by a type family. Here's a hypothetical example: {{{#!hs type family Whoami (ty :: Type) :: Symbol where Whoami Int = "a number" Whoami Float = "a number" Whoami [_] = "a list of things" Whoami _ = "something else" }}} I would like to write {{{#!hs type Error ty = TypeError (Text "Expected a <...> but got ":<>: Text (Whoami ty)) }}} ---- Even when ‘inlined’, it displays `Expected a GRUE but got 'Text (Whoami Int)` and not `• Expected a GRUE but got a number.`: {{{#!hs a :: TypeError (Text "Expected a GRUE but got ":<>: Text (Whoami Int)) a = 'a' }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12048 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12048: Allow CustomTypeErrors in type synonyms (+ evaluate nested type family?) -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: | CustomTypeErrors 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 Iceland_jack: @@ -1,2 +1,2 @@ - I didn't find a ticket with this, but with wiki:CustomTypeErrors you can't - define a type synonym without it erroring: + I didn't find a ticket with this, but with wiki:Proposal/CustomTypeErrors + you can't define a type synonym without it erroring: New description: I didn't find a ticket with this, but with wiki:Proposal/CustomTypeErrors you can't define a type synonym without it erroring: {{{#!hs -- error: … -- • onetwothree -- • In the type synonym declaration for ‘ERROR’ -- Compilation failed. type ERROR = TypeError (Text "onetwothree") }}} but I often want to abstract over error messages since they are clunky to write at the type level and I often use a similar message in many different type families, especially when they can be determined by a type family. Here's a hypothetical example: {{{#!hs type family Whoami (ty :: Type) :: Symbol where Whoami Int = "a number" Whoami Float = "a number" Whoami [_] = "a list of things" Whoami _ = "something else" }}} I would like to write {{{#!hs type Error ty = TypeError (Text "Expected a <...> but got ":<>: Text (Whoami ty)) }}} ---- Even when ‘inlined’, it displays `Expected a GRUE but got 'Text (Whoami Int)` and not `• Expected a GRUE but got a number.`: {{{#!hs a :: TypeError (Text "Expected a GRUE but got ":<>: Text (Whoami Int)) a = 'a' }}} -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12048#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12048: Allow CustomTypeErrors in type synonyms (+ evaluate nested type family?) -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: diatchki Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: | CustomTypeErrors 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 simonpj): * owner: => diatchki -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12048#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12048: Allow CustomTypeErrors in type synonyms (+ evaluate nested type family?) -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: diatchki Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: | CustomTypeErrors 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 Iceland_jack: @@ -12,4 +12,4 @@ - but I often want to abstract over error messages since they are clunky to - write at the type level and I often use a similar message in many - different type families, especially when they can be determined by a type - family. Here's a hypothetical example: + but I often want to factor out error messages, they are clunky to write at + the type level and I often want to reuse message in many different type + families, especially when they can be determined by a type family. Here's + a hypothetical example: New description: I didn't find a ticket with this, but with wiki:Proposal/CustomTypeErrors you can't define a type synonym without it erroring: {{{#!hs -- error: … -- • onetwothree -- • In the type synonym declaration for ‘ERROR’ -- Compilation failed. type ERROR = TypeError (Text "onetwothree") }}} but I often want to factor out error messages, they are clunky to write at the type level and I often want to reuse message in many different type families, especially when they can be determined by a type family. Here's a hypothetical example: {{{#!hs type family Whoami (ty :: Type) :: Symbol where Whoami Int = "a number" Whoami Float = "a number" Whoami [_] = "a list of things" Whoami _ = "something else" }}} I would like to write {{{#!hs type Error ty = TypeError (Text "Expected a <...> but got ":<>: Text (Whoami ty)) }}} ---- Even when ‘inlined’, it displays `Expected a GRUE but got 'Text (Whoami Int)` and not `• Expected a GRUE but got a number.`: {{{#!hs a :: TypeError (Text "Expected a GRUE but got ":<>: Text (Whoami Int)) a = 'a' }}} -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12048#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12048: Allow CustomTypeErrors in type synonyms (+ evaluate nested type family?) -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: diatchki Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: | CustomTypeErrors 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 RyanGlScott): * cc: RyanGlScott (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12048#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12048: Allow CustomTypeErrors in type synonyms (+ evaluate nested type family?) -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: diatchki Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: | CustomTypeErrors 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 jkarni): * cc: jkarni (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12048#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12048: Allow CustomTypeErrors in type synonyms (+ evaluate nested type family?) -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: diatchki Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: | CustomTypeErrors 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 andrewthad): Just to add information about my current workaround, the example given can be rewritten to use a type family instead: {{{#!hs {-# LANGUAGE DataKinds #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UndecidableInstances #-} import GHC.TypeLits import Data.Kind -- Works just like a type synonym type family Fail where Fail = TypeError (Text "It failed") type family Bad a where Bad a = TypeError (Text "It messed up on " :<>: Text (Whoami a)) type family Whoami (ty :: Type) :: Symbol where Whoami Int = "a number" Whoami Float = "a number" Whoami [_] = "a list of things" Whoami _ = "something else" expr :: Bad [Bool] expr = 5 main :: IO () main = putStrLn "Hello" }}} Everyone on this ticket is probably already aware of this, but I just wanted to document it for passersby like myself who may be less familiar with the issue. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12048#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC