i am using WinHugs - haskell 98 interpreter
Printable View
i am using WinHugs - haskell 98 interpreter
Ah, I see. GHC is the de-facto standard nowadays for real development (Yhc is used a lot for research) and it includes the Data.Function module. I guess you'll have to define it yourself:Code:on :: (b -> b -> c) -> (a -> b) -> a -> a -> c
(g `on` f) x y = f x `g` f y
hi, its me again with a question. I have a function
which multiplies 2 integers and adds a third integer to the result.Code:multAdd :: Expr -> Integer
multAdd (Plus(Mult(Const x)(Const y))(Const z)) = (x * y) + z
eg multAdd (Plus(Mult(Const 2)(Const 4))(Const 5)) gives 13. What i am being asked to do is make a "better" function of typethat does the same as my multAdd function with the only difference being i have to specify what a and b are (that comes from the [(Variable, Integer)] part) at the beginning.eg [("a", 3)("b", 4")] (Plus(Mult(Var "a")(Var "b"))(Const 1)).The part that confuses me is how can i make hugs know that Var "a" = 3 and Var "b" = 4. I guess some sort of pattern matching should be done?I am on the right track?Code:[(Variable, Integer)]-> Expr -> Integer
Not necessarily. I point you in the direction of the Prelude function lookup :: (Eq a) => a -> [(a, b)] -> Maybe b
.
Looks like you know what your doing scarface, been reading the thread as I think your doing what I am doing lol.
i just cant seem to get my head round this haskell language.. i have been doing reading on internet but it is still confusing..so i am trying to get help from somewhere :)
I'm interested to know from whence this exercise comes. I met someone on #haskell yesterday who seemed to be doing the same exercise, but who lived on a different continent.
That might of been me, is that the haskell chat on mibbit? Im finding this really confusing scarface lol, you seem to have got the jist of it though, im still a newb lol :eek:
No, a Russian. The exercise was given to them by their teacher as part of a worksheet, so I'm curious as to whence it originated.
well this is a coursework we have been given for a functional programming module we are doing. i study in london. if some1 in russia is doing same exercise then maybe teachers have some source from where they get the coursework exercises and stuff. and i am a newbie as well when it comes to haskell razgriz21.so its not just you :)..