26

Re: Haskell: questions

ZyK_BotaN wrote:

it is passed...
Well the last line that was possible and so to write:

norm v = prod v $1.0 / sqrt $ sprod v v;

. Two questions. Well. To me priorities with brackets are customarier.  I made 2 steps
Back and nevertheless wrote down so.

norm v = prod v (1.0 / sqrt (sprod v v));

It is norms from the point of view of Haskell? Well  I hope that I terrible did not lose anything from
Such conversion.
And the second question. The designer of type. How I can normalize a vector (3.0, 4.0, 5.0)?
I declared function norm as

norm:: Vector-> Vector

And that substitution worked I should inform somehow on that that it not simply tuple namely the Vector.

27

Re: Haskell: questions

ZyK_BotaN wrote:

it is passed...
What for in brackets took argument?

Well . Took and took. Like broke nothing. Simply () for the present not  to the list
To the description of arguments.

28

Re: Haskell: questions

mayton wrote:

Well. To me priorities with brackets are customarier.

mayton wrote:

It is norms from the point of view of Haskell?

It not . Here do not approve, but it is tolerant quite.

mayton wrote:

and that substitution worked I should inform somehow on that that it not simply tuple namely the Vector.

Should not. Here Vector - a synonym  from 3 .
If you want separate type make either newtype or data.
When alternative  is not present, it is better newtype

29

Re: Haskell: questions

ZyK_BotaN wrote:

should not. Here Vector - a synonym  from 3 .
If you want separate type make either newtype or data.
When alternative  is not present, it is better newtype

And on performance there are any recommendations?

30

Re: Haskell: questions

mayton wrote:

it is passed...
And on performance there are any recommendations?

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)

31

Re: Haskell: questions

ZyK_BotaN,  start up there will be an old variant without explicit instructions of vectors. Then
I will compare when there will be all code is written.

32

Re: Haskell: questions

mayton wrote:

Then
I will compare when there will be all code is written.

In speed - differences will not be. It for .

33

Re: Haskell: questions

mayton wrote:

And on performance there are any recommendations?

On  the heat when calculations you will start to write begins.  here prepares surprises (:

34

Re: Haskell: questions

.  operations with algebra of vectors. There is certainly and other actions
For example checks of conditions and parameter passing in a recursion and cleaning
(Here was a procorf at Java) but the main trunk  lies only on
Calculations Double.

35

Re: Haskell: questions

mayton wrote:

Nutyvidel.  operations with algebra of vectors. There is certainly and other actions
For example checks of conditions and parameter passing in a recursion and cleaning
(Here was a procorf at Java) but the main trunk  lies only on
Calculations Double.

gives surprises for the beginner, in respect of implementation of "cycles"

36

Re: Haskell: questions

ZyK_BotaN wrote:

it is passed...
gives surprises for the beginner, in respect of implementation of "cycles"

Yes I already . But I hope bypass of Cartesian coordinates represents
The solved task.  there or Stepanovsky tail or  recursions.
Yes... I started to collect all source code. While .

import Text. Printf
width = 512
height = 512
g = [0x0003C712;
0x00044814;
0x00044818;
0x0003CF94;
0x00004892;
0x00004891;
0x00038710;
0x00000010;
0x00000010]
type Vector = (Double, Double, Double)
sum:: Vector-> Vector-> Vector
sum (x1, y1, z1) (x2, y2, z2) = (x1 + x2, y1 + y2, z1 + z2)
prod:: Vector-> Double-> Vector
prod (x, y, z) (r) = (r * x, r * y, r * z)
sprod:: Vector-> Vector-> Double
sprod (x1, y1, z1) (x2, y2, z2) = x1 * x2 + y1 * y2 + z1 * z2
norm:: Vector-> Vector
==> norm (x, y, z) = prod (x, y, z) (1.0 / sqrt (sprod ((x, y, z) (x, y, z))));

I smoke. A dog .

card.hs:38:54: error:
* Couldn't match expected type ` (Double, Double, Double)-> Vector'
with actual type ` (Double, Double, Double)'
* The function ` (x, y, z) ' is applied to one argument;
but its type ` (Double, Double, Double) ' has none
In the first argument of ` sprod ', namely ` ((x, y, z) (x, y, z))'
In the first argument of ` sqrt ', namely
` (sprod ((x, y, z) (x, y, z)))'
|
38 | norm (x, y, z) = prod (x, y, z) (1.0 / sqrt (sprod ((x, y, z) (x, y, z))));
| ^^^^^^^^^^^^^^^^^^^

37

Re: Haskell: questions

mayton wrote:

Tsykl there or Stepanovsky tail or  recursions.

By default, in  it is not necessary to write tail, after all it lazy.
But is  cases, when laziness only to the detriment then it is written explicitly "vigorous" . It it is already possible also tail.
For on the beginnings, we try normal, and further  it is measured.

38

Re: Haskell: questions

mayton wrote:

I Smoke. A dog .

It is impossible  after sprod to write, one argument, instead of two turns out that at you

39

Re: Haskell: questions

ZyK_BotaN wrote:

it is passed...
It is impossible  after sprod to write, one argument, instead of two

turns out that at you
Replace on

norm (x, y, z) = prod (x, y, z) (1.0 / (sqrt (sprod (x, y, z) (x, y, z))))

.. And why you did not refuse from  on  a vector if you them are explicit not .
Why not?

norm v = prod v (1.0 / (sqrt (sprod v v)))

40

Re: Haskell: questions

ZyK_BotaN wrote:

it is passed...
It is impossible  after sprod to write, one argument, instead of two

turns out that at you
I.e. in  function invocation registers not:

f (x y)

And:

(f x y)

41

Re: Haskell: questions

ZyK_BotaN wrote:

.. And why you did not refuse from  on  a vector if you them are explicit not .
Why not?

. . . GHCI told APPRX.
A bit later there will be a question on printf, IO.

42

Re: Haskell: questions

I/O, something is time to me  on stdout.
I feel that I  will climb in any jungle. The output order there. Absence side-effect e.t.c. But to me it is necessary
This mechanism in any type to solve the task.

import System. IO
import Text. Printf
--putStr ("Hello")
putStrLn ("Hello" ++ width)
Prelude>:l card.hs
[1 of 1] Compiling Main (card.hs, interpreted)
card.hs:42:1: error:
Parse error: module header, import declaration
or top-level declaration expected.
|
42 | putStrLn ("Hello" ++ width)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Failed, no modules loaded.

43

Re: Haskell: questions

mayton wrote:

I/O, something is time to me  on stdout.

https://www.haskell.org/tutorial/io.html
main:: IO ()
main = do c <- getChar
putChar c

The use of the name main is important : main is defined to be the entry point of a Haskell program (similar to the main function in A C), and must have an IO type, usually IO (). (The name main is special only in the module Main; we will have more to say about modules later.) This program performs two actions in sequence: first it reads in a character, binding the result to the variable c, and then prints the character. Unlike a let expression where variables are scoped over all definitions, the variables defined by <- are only in scope in the following statements.

44

Re: Haskell: questions

For  about monads was: https://habr.com/post/315022/

45

Re: Haskell: questions

WebSharper wrote:

The use of the name main is important :

So you understood, what it is necessary in  to "fulfill" functions with ?

46

Re: Haskell: questions

mayton wrote:

import System. IO
import Text. Printf

What for to you this import? What therefrom functions you use?

47

Re: Haskell: questions

ZyK_BotaN wrote:

it is passed...
What for to you this import? What therefrom functions you use?

It is casual noise which remained from samples. Tried putStr, printf.

48

Re: Haskell: questions

WebSharper wrote:

it is passed...
https://www.haskell.org/tutorial/io.html
main:: IO ()
main = do c <- getChar
putChar c

The use of the name main is important : main is defined to be the entry point of a Haskell program (similar to the main function in A C), and must have an IO type, usually IO (). (The name main is special only in the module Main; we will have more to say about modules later.) This program performs two actions in sequence: first it reads in a character, binding the result to the variable c, and then prints the character. Unlike a let expression where variables are scoped over all definitions, the variables defined by <- are only in scope in the following statements.

And it is possible somehow  these  for the theory? I after all need to arrange
Some calls of functions.
As a matter of fact I speak - Okej. You adjusted to operation with STDOUT the difficult theory only for this purpose
That all previous theories did not break. But I - as that king in  to a song
Asked "Only oils for a breakfast to me a tax".
Yes forgive me my impatience but what here not and why output did not work?

main = do
putStr "Enter you name:"
name <- getLine
putStr ("Hello" ++ name)

49

Re: Haskell: questions

mayton wrote:

And it is possible somehow  these  for the theory? I after all need to arrange
Some calls of functions.

Well so while you also should not know these theories.

50

Re: Haskell: questions

mayton wrote:

you adjusted to operation with STDOUT the difficult theory only for this purpose
That all previous theories

did not break
Not absolutely truth. Monads in  and for other purposes. And without monads was .