The difference between "Foo :: Type foreign import data" and simply "Foo data"

Is there any functional difference between the title approaches when defining a foreign type? The approach foreign import data Foo :: Typemakes the intention clearer, but is it?

+4
source share
2 answers

Despite the fact that they look the same on the surface, they differ from each other in their presentation in the metalanguage, since each of them will give different constructions after analysis ( ExternDataDeclarationfor the first, DataDeclarationfor the last).

For example, you can output copies of the data declaration, but an error occurs for the declaration of foreign data.

-- This works
data Empty
derive instance eqEmpty :: Eq Empty
derive instance ordEmpty :: Ord Empty

-- This breaks
foreign import data Empty :: Type
derive instance eqEmpty :: Eq Empty

Error found:

  Cannot derive a type class instance, because the type declaration for Empty could not be found.

Otherwise, you will have to write these instances yourself.

PureScript, , , , . , .

+4

: data X ( Void), import foreign data X :: Type .

, data .

+3

Source: https://habr.com/ru/post/1694425/


All Articles