Page 2 of 5 FirstFirst 1234 ... LastLast
Results 11 to 20 of 44

Thread: Haskell Help

  1. #11
    Join Date
    Oct 2008
    Posts
    20
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default

    i am using WinHugs - haskell 98 interpreter

  2. #12
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #13
    Join Date
    Oct 2008
    Posts
    20
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default

    hi, its me again with a question. I have a function
    Code:
    multAdd :: Expr -> Integer
    multAdd (Plus(Mult(Const x)(Const y))(Const z)) = (x * y) + z
    which multiplies 2 integers and adds a third integer to the result.
    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 type
    Code:
    [(Variable, Integer)]-> Expr -> Integer
    that 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?

  4. #14
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Not necessarily. I point you in the direction of the Prelude function lookup :: (Eq a) => a -> [(a, b)] -> Maybe b.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #15
    Join Date
    Nov 2008
    Location
    UK
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Looks like you know what your doing scarface, been reading the thread as I think your doing what I am doing lol.

  6. #16
    Join Date
    Oct 2008
    Posts
    20
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default

    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

  7. #17
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #18
    Join Date
    Nov 2008
    Location
    UK
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

  9. #19
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #20
    Join Date
    Oct 2008
    Posts
    20
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default

    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 ..
    Last edited by scarface; 11-26-2008 at 04:33 PM. Reason: missed out few things

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •