haskellihaskelloverloaded-strings

How can I set OverloadedStrings in an ihaskell notebook?


I understand from the sample notebook that I should be able to enable and disable extensions as follows:

-- We can disable extensions. 
:ext NoEmptyDataDecls 
data Thing

<interactive>:1:1: error:
    • ‘Thing’ has no constructors (EmptyDataDecls permits this)
    • In the data declaration for ‘Thing’

-- And enable extensions.
:ext EmptyDataDecls
data Thing

However, when I try this with OverloadedStrings, I do not see any success. You can see from the below that T.lines is looking for String rather than Text. Why?

enter image description here

What am I misunderstanding or doing wrong?


Solution

  • Good news: the notebook above does have OverloadedStrings loaded correctly. The problem is you need to read the file with:

    T.readFile
    

    So

    main :: IO ()
    main = do
      text <- T.readFile "./data.txt"
      print $ T.lines text
    

    This was confusing because the error highlighted T.lines rather than readFile. It turns out readFile does not produce a form of textual data that will automatically cast to the format required by T.lines (it produces String, not Text). You had to know that there is an entirely other function to call that does do that. The type system will not convert between these string-like formats for you. You must do this yourself by calling a file-reading function that explicitly returns a Text: here, T.readFile.