简体   繁体   中英

Import Format Library in Haskell

I'm trying to use Format library and the fmt function. I'm getting the error Variable not in scope: fmt:: t1 -> Text .

I'm trying to find the correct import module but can't seem to get it right. I've followed this https://hackage.haskell.org/package/fmt-0.6.3.0/docs/Fmt.html , and I have added {-# LANGUAGE OverloadedStrings #-} and import Fmt at the top of my module, but then get Could not find module 'Fmt'

The function I'm using is:

--This uses the Format library and the fmt function. It is a formatting library. in this case it attaches a name (msg) to a list(of Text), line by line.
allWordsReport :: String -> [Text] -> Text
allWordsReport msg words = 
  fmt $ nameF (fromString msg) $ unlinesF words

I'm struggling with the imports a lot for Haskell. Is there an easy way to find what I need to use, as it seems to be more difficult to find documentation for stuff than other languages.

Are you using stack, cabal or other as your build environment? If you are using cabal primarily, one issue might be not having the library installed in the way GHC needs it. Since I am not building production code and just use Haskell to learn programming concepts, I only use cabal and only have one environment. So for me, I did the below to get it working.

cabal install fmt --lib 

If you are do things correctly for packaging, then, as noted by Sridhar, you should use dependency information in cabal or stack configuration files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM