External Publication
Visit Post

Would keyword arguments conflict with currying in Haskell?

Haskell Community [Unofficial] April 8, 2026
Source

I think I would restrict it to functions having either keyword arguments or positional arguments, so forbidding a combination of the two. In that case you could just consider a function with keyword arguments to be a function from a record type. For example my imagined syntax would be:

magnitude :: {x :: Int, y :: Int} -> Double
magnitude {x = x, y = y} = sqrt (fromIntegral (x * x + y * y))

That could be desugared into:

data MagnitudeArg = MkMagnitudeArg { x :: Int, y :: Int }

magnitude :: MagnitudeArg -> Double
magnitude MkMagnitudeArg {x = x, y = y} = sqrt (fromIntegral (x * x + y * y))

In the Purescript Haskell dialect you can already write such functions using anonymous records:

magnitude :: {x :: Number, y :: Number} -> Number
magnitude {x, y} = sqrt (x * x + y * y)

And there is a proposal to add support for it to GHC (although it is a lot more ambitious):

github.com/ghc-proposals/ghc-proposals

Add Structural Types (Row Polymorphism) (#180)

masterjvanbruegge:row-polymorphism

opened 09:22AM - 09 Nov 18 UTC

        jvanbruegge
      

+201 -0

Record types in Haskell are just syntactic sugar over normal product types, this… prevents us from specifying functions that work for certain structures of records. Rendered

Discussion in the ATmosphere

Loading comments...