What does "task xa = task" mean in the implementation of the Elm task?

In this Github example, the task type is defined as follows:

type Task xa = Task

And then follow a few functions that use this type.

How is the type of task supposed to be understood?

What does this mean when we define a type as:

type Foo ab = Foo

Is Task a specific case when we rely on the built-in implementation of Javascript tasks?

+4
source share
2 answers

Is Task a specific case when we rely on the built-in implementation of Javascript tasks?

That's right. You will notice that the Task type, but not the Task tag (the thing on the right) is exported from the module, so you cannot actually access the latter. This is a placeholder to make the type system happy.

Instead, the built-in JavaScript implementation knows what tasks really exist, namely the JS object . Any secret module associated with tasks (either the Task module or any third-party library, for example elm-http ) is kept secret. However, the Task module exports a large number of helper functions, which can have great control over tasks using only libraries that have already been published.

Editing clarifications. Yes, you need to use a third-party library to get a task that really affects the outside world. To complete this task, you need to send it through the port; until you do this, the task is simply a description of the work being done.

+6
source

It seems that he is creating a kind of wild card.

In the following code:

 import Html exposing (..) type Dog a = Fido myFunc: Dog Int -> String myFunc myDog = "Wouf Wouf" main = text (myFunc Fido) 

myFunc expects a Dog Int . Then you can send Fido to the method.

0
source

All Articles