What is the purpose of including the type in its definition in haskell?

dimid

I'm a beginner in haskell and I wonder about the right way to define a new type. Suppose I want to define a Point type. In an imperative language, it's usually the equivalent of:

data Point = Int Int

However in haskell I usually see definitions such as:

data Point = Point Int Int

What are the differences and when should each approach be used?

karakfa

In OO languages you can define a class with something like this

class Point {
   int x,y;
   Point(int x, int y) {...
}

it's similar

data Point = ...

is the type definition (similar to class Point above , and

     ...  = Point Int Int

is the constructor, you can also define the constructor with a different name, but you need a name regardless.

data Point = P Int Int

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

convert Ocaml/Haskell type definition to Haskell: * in definition

Haskell: What is the definition for '{' '}' and ','?

Recursive conditional definition including summation in Haskell

What is the purpose of the LANGUAGE keyword in Haskell?

Including a module swallows its type

What is the purpose of the brackets {} after a gRPC method definition?

What is the purpose of the addFingerPrint property in a page template definition?

What is the purpose of a struct template without definition?

Haskell function incompatible type and definition

What is UI Bootstrap and what is its purpose?

What is "..." in Angular2? What its purpose?

What is yum - q and what's its purpose?

What is the definition of a callable type?

What is definition of reference type?

What is the purpose of the unit type in Rust?

What is the purpose of `boolean` type in JVM?

What is the Purpose of the Item type in Foundation

What is the purpose of `__metaclass__ = type`?

What is the purpose of {} in the returning type of a function?

What is the purpose of casting into "object" type?

What is the purpose of a type lifetime bound?

__ctype_b_loc what is its purpose?

Kotlin - coroutine yield() what is its purpose?

Webpack postcss loader, what's its purpose?

Inner Class. What is its purpose?

.NET MySqlCommand.Transaction - what is its purpose?

What is React Native's bundle, and its purpose?

What is the purpose of the function (toEnum . fromEnum) in Haskell code?

What purpose does the complexity of `Except` serve in Haskell?