I'm pretty new in Haskell programming. I want to call some functions and save the result in a variable but I don't know how. I read couple of chapters about haskell function in two different book but still don't understand how to do it.
import Data.Map (Map)
import qualified Data.Map as M hiding (Map)
newtype GenEnv elt = Env (Map Id elt)
newEnv :: GenEnv elt -- initialise
newEnv = Env M.empty
newtype GenEnv elt = Env (Map Id elt)
newEnv :: GenEnv elt -- initialise
newEnv = Env M.empty
getEnv :: GenEnv elt -> Id -> Maybe elt -- G(x) (key function)
getEnv (Env env) var = M.lookup var env
union :: GenEnv elt -> (Id,elt) -> GenEnv elt -- G[x:v]
union (Env env) (key,elt) = Env (M.insert key elt env)
-- foldr is faster than addToFM_list!
unionL :: GenEnv elt -> [(Id,elt)] -> GenEnv elt -- list union
unionL (Env env) pairs = Env $ foldr (\(k,e) g -> M.insert k e g) env pairs
What I'm asking here is NOT for somebody to do my work, asking how to call the functions because I don't understand their signature.
GenEnvandnewEnvare declared twise. Is it a typo?fansI think people need a bit more help figuring out what you are ultimately aiming at. I wonder if you see all these functions likeupdatefilterinsertetc. that take you from one Map to another, and wonder, but how do I build up a Map to begin with? How do I get to the point of using these functions? If that's the problem, then there are a number of answers, but the simple-minded answer is by usingfromListfromAscListetc. You start with a list, e.g. of key value pairs, usefromList, engage in fancy Data.Map manipulations, then return to list-land withtoListand co.