
Following is a simple program which uses monadic type binder. I dont understand that how can the last labda function 'F2' has access to value 'val1' since it was passed to the input of 'F1' and was not an input to 'F2' (>>?) :: Maybe a -> (a -> Maybe b) -> Maybe b Nothing >>? _ = Nothing Just v >>? f = f v var_access_test val = Just (val, (val + 1)) >>? \(val1, s) -> Just (s, (s + 1)) >>? -- F1 \(val2, s) -> Just (val, (val1, (val2, (s)))) -- F2 -- I guess -- F2 :: (Int, Int) -> Maybe (Int, (int, (Int. Int))) -- So how can the F2 function return 'val1' even though it was not an input to it. -- output of var_access_test 3 -- Just (3,(3,(4,5))) Although this might be something very trivial but I am stuck here and not able to understand how this is working. (considering the functions to be pure they can only access values passed to them as input). - Divam