Cardinalities on guide.elm-lang.org

On https://guide.elm-lang.org/appendix/types_as_sets.html it states that:

And if you define type Point = Point Float Float then cardinality( Point ) is equivalent to cardinality( (Float, Float) ).

I understand this a point in 2D, but i don’t understand why it is not writting as type Point = Float Float ? Recursion?

There are two different namespaces here, so the same name can be used for two things. If that wasn’t allowed, we might write.

type PointType = PointConstructor Float Float

One is a type you use in type signatures. The other is a function that creates instances of that that type.

You could do an alias without the constructor:

type alias Point = (Float, Float)

But to have a true custom type with full type safety, you need a constructor.

1 Like

Elm custom types are tagged unions so, you need a tag.

That is helpful,
so you need to set the constructor function explicitely with a type x = declaration/creation;
it is not derived from x

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.