
#52: Parenthesize types in bindings, to allow function types without parentheses --------------------+------------------------------------------------------- Reporter: guest | Type: defect Status: new | Priority: normal Milestone: | Component: general Version: 0.16.0 | Keywords: --------------------+------------------------------------------------------- c2hs allows arbitrary types in function bindings. However, a function type such as {{{T1 -> T2}}} will cause the generated code to parse incorrectly; since c2hs does not parenthesize each argument type, the argument and return types of the function type will parse as multiple arguments of the binding type, rather than as a single argument of function type. The binding can work around this by explicitly parenthesizing the function type, but since c2hs already requires quoting the entire type, the need for parentheses does not become apparent without reading the generated code (or encountering a compile error). Add parentheses around the types in bindings, so that unparenthesized function types as arguments will parse correctly. {{{ diff -rN -u old-c2hs/src/C2HS/Gen/Bind.hs new-c2hs/src/C2HS/Gen/Bind.hs --- old-c2hs/src/C2HS/Gen/Bind.hs 2012-10-07 20:49:16.773294894 -0700 +++ new-c2hs/src/C2HS/Gen/Bind.hs 2012-10-07 20:49:16.789294705 -0700 @@ -913,8 +913,8 @@ ctxt = case octxt of Nothing -> "" Just ctxtStr -> ctxtStr ++ " => " - argTys = [ty | CHSParm im ty _ _ _ <- parms' , notVoid im] - resTys = [ty | CHSParm _ ty _ om _ <- parm':parms', notVoid om] + argTys = ["(" ++ ty ++ ")" | CHSParm im ty _ _ _ <- parms' , notVoid im] + resTys = ["(" ++ ty ++ ")" | CHSParm _ ty _ om _ <- parm':parms', notVoid om] resTup = let (lp, rp) = if isPure && length resTys == 1 then ("", "") }}} -- Ticket URL: http://hackage.haskell.org/trac/c2hs/ticket/52 c2hs http://www.cse.unsw.edu.au/~chak/haskell/c2hs/ C->Haskell, An Interface Generator for Haskell