मैं फ़ंक्शन लिखना चाहता हूं और स्ट्रिंग को परिणाम देना चाहता हूं।हास्केल आईओ (स्ट्रिंग) और स्ट्रिंग
read' :: FilePath -> String
मैं का उपयोग करें::
मैं समारोह चाहते
:t readFile
readFile :: FilePath -> IO String
मैं:
read' :: IO()
read' = do
str <- readFile "/home/shk/workspace/src/test.txt"
putStrLn str
मैं str पूछना चाहता हूँ स्ट्रिंग है या नहीं?
हम जानते हैं कि:
:t putStrLn
putStrLn :: String -> IO()
तो फिर मैं नहीं कर सकता:
read' :: String
read' = do
str <- readFile "/home/shk/workspace/lxmpp/src/test.txt"
str
मैं त्रुटि मिलती है कि:
Couldn't match expected type `[t0]' with actual type `IO String'
In the return type of a call of `readFile'
In a stmt of a 'do' expression:
str <- readFile "/home/shk/workspace/lxmpp/src/test.txt"
In the expression:
do { str <- readFile "/home/shk/workspace/src/test.txt";
str }
धन्यवाद।
पढ़ाई में पढ़ा गया फ़िल का तात्पर्य है कि आप आईओ मोनैड में हैं, और आईओ मोनड से बच नहीं सकते! – is7s
@ is7s जब तक आप 'unsafePerformIO' का उपयोग नहीं करते हैं! – alternative
असुरक्षित पैराफॉर्मियो का पहला नियम है कि आप किसी को भी असुरक्षित जानकारी के बारे में नहीं बताते हैं! –