I am using Data.Sequence.mapWithIndex to access the index of the element in the list xs in the current iteration of the map function. However how would it be possible to access the xs list (present in the prefixRule function) inside the checkPrefix function ?
checkPrefix :: Int -> LocalType -> LocalType
checkPrefix index (Act dir s lt) = do
-- here i would want to have access to the list xs in the prefixRule function
...
prefixRule :: [Localtype] -> IO()
prefixRule sequent = do
let newlist = S.mapWithIndex checkPrefix (S.fromList xs)
...
CodePudding user response:
You can work with partial application. You can rewrite the checkPrefix
function to:
checkPrefix :: [LocalType] -> Int -> LocalType -> LocalType
checkPrefix xs index (Act dir s lt) = …
here the first parameter xs
is thus a reference to the entire list xs
.
and then rewrite prefix to:
prefixRule :: [LocalType] -> IO ()
prefixRule sequent = do
let newlist = S.mapWithIndex (checkPrefix xs) (S.fromList xs)
…