foundation icon indicating copy to clipboard operation
foundation copied to clipboard

openFile function not accessible

Open flip111 opened this issue 8 years ago • 2 comments

Hello, i'm trying to use openFile. With help i found out that the Foundation.IO.File module is internal and i can't use this function. Is there something that can be done about this in the foundation package?

flip111 avatar Jan 24 '17 20:01 flip111

I think this is related

module Main where

import Foundation
import System.Directory (getCurrentDirectory)

main :: IO ()
main = getCurrentDirectory >>= putStrLn
Main.hs:7:32: error:
    • Couldn't match type ‘[Char]’ with ‘String’
      Expected type: GHC.IO.FilePath -> IO ()
        Actual type: String -> IO ()
    • In the second argument of ‘(>>=)’, namely ‘putStrLn’
      In the expression: getCurrentDirectory >>= putStrLn
      In an equation for ‘main’: main = getCurrentDirectory >>= putStrLn

Edit: this is a workaround in case someone else has this problem: getCurrentDirectory >>= \x -> putStrLn (show x)

flip111 avatar Jan 31 '17 10:01 flip111

Also if i try to catch an exception on openFile i have to import a lot of non-foundation stuff

import System.IO (openFile, IOMode(..))
import Control.Exception (try, Handler(..))
import GHC.IO.Handle.Types
import GHC.IO.Exception (ioe_description)

ioe_description gives type String, of which i again get the Couldn't match type ‘[Char]’ with ‘String’ error

flip111 avatar Mar 14 '17 12:03 flip111