[GHC] #13855: Syntactic sugar to write the recursion in GHC
#13855: Syntactic sugar to write the recursion in GHC -------------------------------------+------------------------------------- Reporter: vanto | Owner: (none) Type: feature | Status: new request | Priority: normal | Milestone: Component: Compiler | Version: 8.0.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: -------------------------------------+------------------------------------- The recursion is defined by two case that are a base case and a recursive case.\\ Instead of writing two functions to describe the recursion, I propose to write a single function that makes both.\\ {{{<op>}}} should be set to tell the compiler how to compile the function.\\ syntaxe : {{{ exp = <base_case_exp1;...;base_case_expn> <op> <recursive_case_exp1;...;recursive_case_expn> <recursive_case_guards> }}} examples: {{{ fac :: Int -> Int fac n = 0 = 1 <op> n * fac (n-1) }}} {{{ product :: Num a => [a] -> a product (n:ns) = [] = 1 <op> n * product ns }}} {{{ reverse :: [a] -> [a] reverse (x:xs) = [] = [] <op> reverse xs ++ [x] }}} {{{ insert :: Ord a => a -> [a] -> [a] insert x (y:ys) = x [] = [x] <op> | x <= y = x:y:ys | otherwise = y:insert x ys }}} {{{ drop :: Int -> [a] -> [a] drop n (_:xs) = 0 xs = xs; _ [] = [] <op> drop (n-1) xs }}} {{{ fib :: Int -> Int fib n = 0 = 0; 1 = 1 <op> fib (n-2) + fib (n-1) }}} If someone is interested in this, I encourage him to write a proposal. I don't know how to do it. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13855> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13855: Syntactic sugar to write the recursion in GHC -------------------------------------+------------------------------------- Reporter: vanto | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.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 j.waldmann): Please don't. You want to introduce new syntax for definition of functions? There are very good reasons for what's currently in the Language Standard. In this case: definitions are equations, because we want to do equational reasoning. Your proposal severely obfuscates the equations. I refuse to parse "fib n = 0 = 0". -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13855#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#13855: Syntactic sugar to write the recursion in GHC -------------------------------------+------------------------------------- Reporter: vanto | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.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 vanto): Wearing the hair shirt\\ A retrospective on Haskell\\ Simon Peyton Jones\\ Microsoft Research, Cambridge\\ POPL’03 meeting\\ In the paragraph named {{{Syntax}}} he said:\\ {{{ Syntactic redundancy ... Haskell's choice: provide multiple ways, and let the programmer decide ... }}} And look what he's saying about the difference between {{{declaration style}}} vs {{{expression style}}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13855#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC