Giter Site home page Giter Site logo

Comments (8)

JordanMartinez avatar JordanMartinez commented on August 25, 2024 2

@srghma Hmm... Good point.

The template and lessons serve as a way to help people get used to the types and what they mean. If they need to write something quick, but want to avoid compiler errors as much as possible, then they should use the template.

Your approach is more for those who are already familiar with Halogen. Still, I'd like to add it as a tip or something at the end of this project. We could encourage people to use that approach once they feel comfortable with Halogen.

from learn-halogen.

JordanMartinez avatar JordanMartinez commented on August 25, 2024 1

@milesfrain Looks like this was fixed in current development branch. I'm not sure when, but I'm going to close this issue in the next release. @srghma Could you open an issue describing your tip and adding it to this project?

Edit: It wasn't fixed in current development branch, but a replace-all didn't take long either.

from learn-halogen.

JordanMartinez avatar JordanMartinez commented on August 25, 2024

Void is a type that doesn't have a runtime value at all. We use that type to indicate 'this code will never run.' Unit is a type that only has one possible value, Unit. In other words, "this code can run." Const is like a placeholder Functor (e.g. when a type signature requires you to use a Functor, but you don't need/want one).

So, Const Void is the correct version because it indicates that it's impossible to ever run the query. That would be absurd, which is why we use absurd to satisfy places in the type signature where such a function is needed.
If we used Const Unit, the query code can still run.

Which places are you referring to?

from learn-halogen.

milesfrain avatar milesfrain commented on August 25, 2024

Which places are you referring to?

The blue links in the original message. They were subtle. Const Void and Const Unit

from learn-halogen.

JordanMartinez avatar JordanMartinez commented on August 25, 2024

I saw that those were links, but I did not click on them. Sorry. That's on me, not you.

Yes, the Const Unit should be Const Void.

from learn-halogen.

srghma avatar srghma commented on August 25, 2024

it's also possible to use forall like

-- approach is used here 
-- https://github.com/purescript-halogen/purescript-halogen/blob/bb715fe5c06ba3048f4d8b377ec842cd8cf37833/examples/higher-order-components/src/Harness.purs#L43
-- https://github.com/purescript-halogen/purescript-halogen/blob/bb715fe5c06ba3048f4d8b377ec842cd8cf37833/examples/components-inputs/src/Container.purs#L39

simpleChildComponent :: forall query input messages . H.Component HH.HTML query () input messages Aff

-- and render using `unit` for values and `absurd` or `const unit` for functions

let index = unit -- or some integer
let input = unit -- or some datatype. On first render passed to `initialState` and to `receive` on subsequent renders if `input` is changed
let messageHandler = absurd -- or `Just <<< HandlePanelMessage`
HH.slot _proxy index simpleChildComponent input messageHandler

instead of

type MyQuery = Const Void
type MyInput = Void
type MyMessages = Void
simpleChildComponent :: H.Component HH.HTML MyQuery () MyInput MyMessages Aff

from learn-halogen.

milesfrain avatar milesfrain commented on August 25, 2024

help people get used to the types and what they mean

The guide is even more terse with the types:

component :: forall q i o m. H.Component HH.HTML q i o m

But I found explicit types most helpful when starting out with this repo.

from learn-halogen.

srghma avatar srghma commented on August 25, 2024

@milesfrain and it's possible to misinterpret m as monad instead of messages

from learn-halogen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.