Search code examples
purescripthalogen

Purescript Halogen Component function: Passing spaced arguments instead of a Record?


I'm on PureScript 0.8.2. In PureScript Halogen, the component function has the signature:

component :: forall s f g. ComponentSpec s f g -> Component s f g

where

-- | A spec for a component.
type ComponentSpec s f g =
  { render :: s -> ComponentHTML f
  , eval :: Natural f (ComponentDSL s f g)
  }

So component expects a record. But in the Halogen Template Project, component is called as follows:

ui = component render eval

Am I looking at two different component functions? or does arguments separated by space get converted into a record? So I tried the following in psci:

> type Point = { x :: Int, y :: Int }

> let
  addP :: Point -> Int
  addP p = p.x + p.y
> addP {x: 4, y: 5 }

9

> addP 4 5

Error found:
in module $PSCI
at  line 1, column 1 - line 1, column 8

  Could not match type

    { x :: Int
    , y :: Int
    }

  with type

    Int
....

Solution

  • Sorry, the template project hasn't been updated yet. Thanks for the reminder!

    Assuming your eval and render functions are in scope you can use field puns to write the component definition this way:

    ui = component { render, eval }
    

    But yes, a record is always required now. I'll update the template project right away.