mayton wrote:

Tried to define new type with Show. It  any. How to understand error status code?
Really I should bypass over 9000 syntactic forms to select one is unique
The correct?

newtype Vector = Double Double Double deriving (Show, Eq)
Prelude&gt;:l card.hs
[1 of 1] Compiling Main (card.hs, interpreted)
card.hs:27:18: error:
* The constructor of a newtype must have exactly one field
but ` Double ' has two
* In the definition of data constructor ` Double'
In the newtype declaration for ` Vector'
|
27 | newtype Vector = Double Double Double deriving (Show, Eq)
| ^^^^^^^^^^^^^^^^^^^^

You like simply vector arranged. And there show it is already implemented.
And so that, you newtype incorrectly wrote down. I above  gave.

ZyK_BotaN wrote:

and so that, you newtype incorrectly wrote down. I above  gave.

newtype Vector = Vector (Double, Double, Double)

Well... I mean while in search.
If to make so

newtype Vector = Vector (Double, Double, Double) deriving (Show, Eq)

That  the Vector transits norms. But scalar product function does not gather for example.

* Couldn't match expected type ` Vector'
with actual type ` (Double, Double, Double)'
* In the pattern: (x2, y2, z2)
In an equation for ` sprod ':
sprod (x1, y1, z1) (x2, y2, z2) = x1 * x2 + y1 * y2 + z1 * z2
|
36 | sprod (x1, y1, z1) (x2, y2, z2) = x1 * x2 + y1 * y2 + z1 * z2

I do not know corrupting scales further...
If I return reversely to tapl-definition of a vector that algebra of vectors  normally.

type Vector = (Double, Double, Double)

But I will define again tostring (.).

mayton wrote:

But I will define again tostring (.).

What for, if for  it is already implemented show?

mayton wrote:

that  the Vector transits norms. But scalar product function does not gather for example.

Logically.
For then so function should look, I above wrote:

ZyK_BotaN wrote:

it is passed...
Differences should not be.
But if you want that  with vectors  differed, here so write:

newtype Vector = Vector (Double, Double, Double)
summation:: Vector-&gt; Vector-&gt; Vector
summation (Vector (x1, y1, z1)) (Vector (x2, y2, z2)) = Vector (x1 + x2, y1 + y2, z1 + z2)

ZyK_BotaN wrote:

it is logical.
For then so function should look, I above wrote:

I.e.

sprod (Vector (x1, y1, z1)) (Vector (x2, y2, z2))

Well... I assumed that such spool

(2.0, 3.0, 4.0) (5.0,7.0,9.0)

To test easier than simply flow Double of numbers. And generally I
Always so arrived with:: toString () or serialization. I defined
The format of essence for convenience of its search in a broad gull or text
To line. In certain cases it could be JSON. But more often
It is simple  entities and in brackets value of a tuple.
Therefore it was important to me to define a format.

mayton wrote:

Therefore it was important to me to define a format.

To you does not approach standard show for a tuple?
Well then  do  and I will teach to do you  ""  in .

For today I grazed. It is necessary somehow it is all to rethink.

mayton wrote:

For today I grazed. It is necessary somehow it is all to rethink.

You in Kiev? It will be possible and somewhere in  to meet.

Will be . Java Day or Scala Day - then it is possible.

mayton wrote:

Scala Day

If you a rock rummage, should and in  much to understand (:

that I as  the burro did not stand between two (three) variants.
1) data Vector
2) type Vector (tuple)
3) newtype Vector
It is possible to summarize that is that? As a matter of fact I search best practices for analog struct from "for a C ++".

mayton wrote:

Vobshchem that I as  the burro did not stand between two (three) variants.
1) data Vector
2) type Vector (tuple)
3) newtype Vector
It is possible to summarize that is that? As a matter of fact I search best practices for analog struct from "for a C ++".

You forgot the fourth - records.
They also will be analog of structures from with ++, for   with names of fields.
And  an expert in , or date or if alternative designers are not present it is possible and .
Records too often use, especially if it is a lot of fields.
.. And I always data , not .

with it. Give data.

mayton wrote:

Chort with it. Give data.

Well I already wrote them, here so look:

data Vector = Vector {x:: Double
, y:: Double
, z:: Double
} deriving (Show, Eq)
sum ':: Vector-&gt; Vector-&gt; Vector
sum ' v1 v2 = Vector ((x v1) + (x v2)) ((y v1) + (y v2)) ((z v1) + (z v2))

ZyK_BotaN wrote:

it is passed...
If you a rock rummage, should and in  much to understand (:

At me is not present  experience in Scala. The hobby is simple.

ZyK_BotaN, and what for an apostrophe after sum '?

mayton wrote:

Give data.

Here:

data Vector = Vector Double Double Double deriving (Show, Eq)
sum ':: Vector-&gt; Vector-&gt; Vector
sum ' (Vector x1 y1 z1) (Vector x2 y2 z2) = Vector (x1 + x2) (y1 + y2) (z1 + z2)

mayton wrote:

ZyK_BotaN, and what for an apostrophe after sum '?

As in Prelude unit already function with such name is.

ZyK_BotaN wrote:

it is passed...
As in Prelude unit already function with such name is.

And this unit, boots in ghci by default and superimposes our total.

mayton wrote:

it is passed...
At me is not present  experience in Scala. The hobby is simple.

Well such case class you know? ))

ZyK_BotaN wrote:

it is passed...
As in Prelude unit already function with such name is.

... . Simply  alpha-num in identifiers to use. Unusually.

mayton wrote:

it is passed...
... . Simply  alpha-num in identifiers to use. Unusually.

In  the apostrophe - is norm for the declaration of new functions (or variable constants) with the same name.
And apostrophes can be increased on .
x =...
x ' = f x
x "= g x'
x ' "= k x"
And so on.
And in a recursion here so it is possible to use:
f x = let x ' = e x
in f x'