2

Newbie playing with haskell stack scripting and turtle.

  • Created a folder stack-scripts. Thought if it looks good, then I'll create some haskell utils for me to replace bash scripts.
  • Created a file named turtle.hs with following text:

    #!/usr/bin/env stack
    -- stack --resolver lts-11.2 script
    
    {-# LANGUAGE OverloadedStrings #-}
    
    import Turtle
    
    main = echo "Hello!"
    
  • made the chmod +x turtle.hs and tried to execute it.

  • Got the following error message:

    turtle.hs:1:1: error:
        File name does not match module name:
        Saw: `Main'
        Expected: `Turtle'
      |
    1 | #!/usr/bin/env stack
      | ^
    

It does what it should if I rename turtle.hs to turtle.sh. But then I have no syntax highlighting for haskell.

Also it works if I rename it to something-other.hs. But then Haskero (VSCode) complains about import Turtle line: Couldn't guess that module name. Does it exist?

What I'm missing here? Running in git bash on Windows.

python_kaa
  • 1,034
  • 13
  • 27

1 Answers1

3

Apparently you need to give the script a different name as the module name in which the code runs, will automatically be derived from it and now it will conflict with the imported Turtle module. Renaming it to turtlescript.hs and then

#!/usr/bin/env stack
-- stack --resolver lts-11.2 script --package turtle

{-# LANGUAGE OverloadedStrings #-}

import Turtle

main :: IO ()
main = echo "Hello!"

worked for me.

Michiel Borkent
  • 34,228
  • 15
  • 86
  • 149
  • Thanks, works for me too! Not sure about last part - `Haskero` highlighting an error on `import`. Should I do install turtle somehow or is it pure `Haskero` issue not working correctly in this case? – python_kaa Mar 29 '18 at 10:46
  • I'm not sure if stack scripts are supported in various IDEs. In intero (Emacs) I also get a red curly. If you want proper IDE support you might want to use a proper stack / cabal project. – Michiel Borkent Mar 29 '18 at 11:00