Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Use of mapWithIndex function

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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)
    …
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading