windowshaskellvisual-studio-codehaskell-stackhaskero

File name does not match module name


Newbie playing with haskell stack scripting and turtle.

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.


Solution

  • 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.