D
D
Danil Shchuchkin2020-05-08 14:14:19
Haskell
Danil Shchuchkin, 2020-05-08 14:14:19

How easy is it to implement reading/writing files in Haskell?

I need to create a database (for educational purposes) in Haskell. I can’t figure out how to implement data entry through the console with further saving to a file, as well as reading data from the generated file. There is little clear (in my opinion) literature on Haskell on the Internet, can you tell me where you can see examples of such constructions. Thanks in advance, don't kick too much :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2020-05-09
@varkrift

Quite simply (very simplistic)

module Main where

import System.IO

main :: IO ()
main = do
  content <- readFile "file.dat"
  putStrLn content

  putStr "enter x = "

  -- Флюшим вывод не забываем про ленивость языка
  hFlush stdout 

  x <- getLine 

  print (read x :: Int)

  writeFile "file.dat" x

The rest is within the framework of understanding the language.
About Haskell in a human way (D.Shevchenko)
https://www.ohaskell.guide
A.Kholomyev (more advanced)
https://anton-k.github.io/en-haskell-book/book/hom...
Well, Lipovach learnyouahaskell.com is in Russian
Will Kurt "Program in haskell" too.
Everything else (and this is a lot of things) is more for those who need it.
In any case, you can look for answers here https://wiki.haskell.org/Haskell
For example, start with https://wiki.haskell.org/Introduction_to_IO there is a section
Further reading
Need this --> For a comprehensive tutorial on using IO monad, look at the Haskell I/O inside: Down the Rabbit's Hole

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question