I am new to Haskell, and I am trying to write a function that replaces the first and the last element of a an array. When writing my code in GHCI, it works fine, but in VS Code it gives an error saying "parse error". My guess is that "let" works not the way that I assumed. Here is the function:
swap1 :: [x] -> [x]
swap1 [] = error "empty list"
swap1 [x] = error "one element list"
swap1 let a = head x
swap1 let b = last x
swap1 let y = init x
swap1 let z = tail y
swap1 = b:z ++ [a]
let
.swap1 let a = head x
is just nonesense.let a = head x
(provided thatx
is defined) defines a new variable on ghci, which of course is not nonesense,swap1 let a = head x
however is.