Comments (8)
@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.
@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.
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.
Which places are you referring to?
The blue links in the original message. They were subtle. Const Void
and Const Unit
from learn-halogen.
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.
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.
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.
@milesfrain and it's possible to misinterpret m
as monad
instead of messages
from learn-halogen.
Related Issues (20)
- `--no-minify` is not supported by `serve` action of `parcel` HOT 4
- Link to 'Styling Question' and its links
- Update project to 0.13.4 PS release
- log element's text? HOT 2
- Upgrade project to PS 0.13.5
- Upgrade project to Spago 0.12.1
- Add CI build for local-based installation
- Whatβs best practice/pattern for cross component communication HOT 1
- Add tip from Gary for rendering valid/invalid input data
- Add exercises for each example HOT 7
- launchAff_ vs runHalogenAff HOT 2
- Link to 'template repo' for Halogen
- Recommend spago's --watch feature in automatic reload instructions HOT 6
- Integrate examples with `halogen-storybook`
- Change `purescript-jordans-reference` links to use its `latestRelease` branch? HOT 6
- Which to cover first? Halogen Hooks or Halogen Components? HOT 9
- use forall instead of Void for empty queries, messages, inputs HOT 1
- Link to statebox's fork of halogen-svg
- Feature Request: convert to mdBook HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from learn-halogen.