[Haskell-beginners] Text.XML.writeFile question

Alan Buxton alanbuxton at gmail.com
Mon Aug 12 22:35:30 CEST 2013


Hi

 

I am trying to write an XML file where the filename is created based on a
timestamp. Simplified version below. This won't compile - I get this error
in doWrite2 

 

filepathtest.hs|24 col 17 error| Couldn't match expected type
`system-filepath-0.4.7:Filesystem.Path.Internal.FilePath'


||             with actual type `String'

|| In the second argument of `writeFile', namely `t1'

|| In a stmt of a 'do' block: writeFile def t1 doc

|| In the expression:

||   do { t1 <- tsString;

||        writeFile def t1 doc }

 

Somehow the String "text.xml" in doWrite1 is converted into a FilePath, but
not the String t1 in doWrite2. What am I doing wrong?

 

  {-# LANGUAGE OverloadedStrings #-}

  module Filepathtest  where

  

  import Text.XML

  import Data.Time.Clock.POSIX (utcTimeToPOSIXSeconds)

  import Data.Time.Clock  (getCurrentTime)

  import Prelude hiding (writeFile, FilePath)

    

  tsString :: IO String

  tsString = do

    x <- getCurrentTime

    let x' = show $ floor $ utcTimeToPOSIXSeconds x

    return x'

  

  doWrite1 :: Document -> IO ()

  doWrite1 doc =

    writeFile def "test1.xml" doc

  

  doWrite2 :: Document -> IO ()

  doWrite2 doc = do

    t1 <- tsString

    writeFile def t1 doc

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130812/64e2b900/attachment.htm>


More information about the Beginners mailing list