76

Re: Haskell: questions

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>: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.

77

Re: Haskell: questions

ZyK_BotaN wrote:

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

newtype Vector = Vector (Double, Double, Double)

78

Re: Haskell: questions

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 (.).

79

Re: Haskell: questions

mayton wrote:

But I will define again tostring (.).

What for, if for  it is already implemented show?

80

Re: Haskell: questions

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-> Vector-> Vector
summation (Vector (x1, y1, z1)) (Vector (x2, y2, z2)) = Vector (x1 + x2, y1 + y2, z1 + z2)

81

Re: Haskell: questions

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))

82

Re: Haskell: questions

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.

83

Re: Haskell: questions

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 .

84

Re: Haskell: questions

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

85

Re: Haskell: questions

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.

86

Re: Haskell: questions

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

87

Re: Haskell: questions

mayton wrote:

Scala Day

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

88

Re: Haskell: questions

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 ++".

89

Re: Haskell: questions

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 .

90

Re: Haskell: questions

with it. Give data.

91

Re: Haskell: questions

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-> Vector-> Vector
sum ' v1 v2 = Vector ((x v1) + (x v2)) ((y v1) + (y v2)) ((z v1) + (z v2))

92

Re: Haskell: questions

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.

93

Re: Haskell: questions

ZyK_BotaN, and what for an apostrophe after sum '?

94

Re: Haskell: questions

mayton wrote:

Give data.

Here:

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

95

Re: Haskell: questions

mayton wrote:

ZyK_BotaN, and what for an apostrophe after sum '?

As in Prelude unit already function with such name is.

96

Re: Haskell: questions

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.

97

Re: Haskell: questions

mayton wrote:

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

Well such case class you know? smile))

98

Re: Haskell: questions

ZyK_BotaN wrote:

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

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

99

Re: Haskell: questions

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'

100

Re: Haskell: questions

ZyK_BotaN wrote:

it is passed...
Well such case class you know? smile))

Esteemed. Now I know. smile  the tracer of a ray on Scala - . Too the task.
I completed it but there were bugs.