Closed FloWi closed 2 years ago
whole file
module Ch5 where
import Data.List (List(..), (:))
import Data.Maybe (Maybe(..))
import Effect (Effect)
import Effect.Class.Console (log)
import Prelude (Unit, discard, negate, show, ($), (+), (==))
test :: Effect Unit
test = do
log """log $ show $ findLastIndex (_ == 10) (Nil :: List Int)"""
log $ show $ findLastIndex (_ == 10) (Nil :: List Int)
log """log $ show $ findLastIndex (_ == 10) (10 : 5 : 10 : -1 : 2 : 10 : Nil) """
log $ show $ findLastIndex (_ == 10) (10 : 5 : 10 : -1 : 2 : 10 : Nil)
log """log $ show $ findLastIndex (_ == 10) (10 : 5 : 10 : -1 : 2 : 10 : 5 : Nil) """
log $ show $ findLastIndex (_ == 10) (10 : 5 : 10 : -1 : 2 : 10 : 5 : Nil)
log """log $ show $ findLastIndex (_ == 10) (11 : 12 : Nil)"""
log $ show $ findLastIndex (_ == 10) (11 : 12 : Nil)
findLastIndex :: forall a. (a -> Boolean) -> List a -> Maybe Int
findLastIndex _ Nil = Nothing
findLastIndex pred xs = go 0 Nothing xs
where
go :: Int -> Maybe Int -> List a -> Maybe Int
go _ res Nil = res
go i res (y : ys) = go (i + 1) newRes ys
where
newRes = if (pred y) then Just i else res
Good catch! I don't know why this would happen. If the parser can't parse the code the formatter won't format. I wonder if this could be a problem with the parser.
This is an issue with the parser. https://github.com/natefaubion/purescript-language-cst-parser/issues/24
That's good news, @natefaubion. I'm glad my newbieness to a language with significant whitespaces could bring a bug to the surface :)
@FloWi this should work now with version 0.11.2 of the formatter.
Yes, it works fine. The formatter doesn't delete anything and the where
is now highlighted as an unexpected token. Thanks for the fix @natefaubion and for the update @i-am-the-slime!
when formatting this code (with a wrong indentation of the
where
in thego
function)the whole body of the
go
function is removed.correct code
This might not be the best purescript code, since I'm still learning purescript, but I don't expect the formatter deleting nonempty lines.