I am learning Haskell and I am having a hard time performing the following task.
I have a script that gives me a directory. I would like to call that script, get the directory and then use the "cd" in Turtle to change the directory. Below is the code that I currently wrote but it fail to compile.
It says lineToText targetDirLine
expects Line
and not Maybe Line
. I do not understand why fold (inshell "getSomeDir" empty) Fold.head
produces Maybe (Maybe Line)
.
Even after fixing this error I get other issue using cd
.
#!/usr/bin/env stack
-- stack --resolver lts-10.2 script
{-# LANGUAGE OverloadedStrings #-}
import qualified Control.Foldl as Fold
import Turtle
getDirAndCd :: MonadIO io => io ()
getDirAndCd = cd fp
where (Just targetDirLine) = fold (inshell "getSomeDir" empty) Fold.head
fp = fromText (lineToText targetDirLine)
What am I missing?