
#12376: Allow function definitions in record syntax -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 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 Iceland_jack): I'm not sure about that, it's possible that there would be more ''bang''-per-''buck'' in extending `LambdaCase` with `\case2`, `\case3`. Take an example of dictionary translation from [https://skillsmatter.com/skillscasts/8978-checking-and-translating-type- classes Checking and translating type classes]: {{{#!hs import Prelude hiding (Eq (..)) data Eq a = MkEq { (==) :: a -> a -> Bool , (/=) :: a -> a -> Bool } }}} {{{#!hs -- Default definition of (/=) neqDef :: Eq a -> a -> a -> Bool neqDef = not .:: (/=) where (.::) = fmap.fmap.fmap eqList :: forall a. Eq a -> Eq [a] eqList a = MkEq { (==) = aux , (/=) = neqDef (eqList a) } where aux :: [a] -> [a] -> Bool aux [] [] = True aux (x:xs) (y:ys) = (==) a x y && (==) (eqList a) xs ys aux _ _ = False }}} Now if we wanted to inline `aux` using this ticket, they would presumably translate into lambdas (single clause): {{{#!hs eqList a = MkEq { a == b = case (a, b) of ([], []) -> True (x:xs, y:ys) -> ... (_, _) -> False -- Translates into -- -- eqList a = MkEq -- { (==) = \a b -> ... }}} A hypothetical `\case2` may be better {{{#!hs eqList a = MkEq { (==) = \case2 ([], []) -> True (x:xs, y:ys) -> ... (_, _) -> False , (/=) = neqDef (eqList a) } }}} Given an extension that allows user to omit tuple parentheses when un- ambiguous (similar to Agda's `_,_` constructor which looks like `a , b` when applied to two arguments) this looks even better {{{#!hs eqList a = MkEq { (==) = \case2 [], [] -> True x:xs, y:ys -> ... _, _ -> False , (/=) = neqDef (eqList a) } }}} Should I create a ticket for these ideas or use the new [https://github.com/ghc-proposals/ghc-proposals GHC Proposals]? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12376#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler