A
A
alan4042019-12-15 13:56:29
Haskell
alan404, 2019-12-15 13:56:29

Haskell program, how to output structure data?

Data structure: country; reserve; number of species of rare animals in the reserve. Create two queries that allow you to display the list "Country - number of reserves" and a list of those reserves where the most rare species are.
Tell me how to display the list Country - number of reserves
Structure example
i1 = Reserves {
country = "Russia",
reserve = "RoevRuchey",
animalsCount = 8056
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kornietsbk, 2020-07-23
@kornietsbk

Let's say we have a structure:

data Struct = Constructor {
       field :: String,
       value :: Integer
              }
       deriving (Show)

Next, we initialize it with some value: Now the item name is associated with the Struct type. To get the values ​​of individual fields, you can use the names of these fields as a function (only if you use the syntax shown in the example) :
Prelude> let item = Constructor "Module" 100
Prelude> field s
"Module"
Prelude>value s 
100

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question