Advanced Search

Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 31

Thread: Learning Haskell

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

    Default

    There's no such way in Haskell because there's no way of telling what "the last result" is. Haskell programs are executed in the order necessary, not the order you set them out in the source file. There may be a way to do it in your command-line interpreter, however.
    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!

  2. #22
    Join Date
    Dec 2007
    Posts
    0
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    you can do it in winhugs

  3. #23
    Join Date
    Jun 2008
    Posts
    0
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I need help quickly please. I got one problem to solve in Haskell, not very
    hard but I don't know anything about Haskell programming language so I must
    ask for help here and hope for (positive) answer.

    So, the question goes like this:

    Write function in Haskell which delete every member of a list that is bigger
    then the member after him. Test function on list of Integers and on list of
    Doubles.

    You may use your own functions for help but you may not use functions from
    extra Haskell libraries.


    Can someone help me please!

  4. #24
    Join Date
    Jun 2008
    Posts
    0
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Anyone???

    Please!

  5. #25
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    this sounds alot like a homework assignment.

    i suggest reading your text book

  6. #26
    Join Date
    May 2007
    Location
    USA
    Posts
    373
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    Hint: Split your function into two functions. The first one would be the one that the coder uses on a regular basis. The second would be the one that the first function uses behind the scenes for help (called a helper function).

    I'll give you some of the code. Try filling in the rest (in the ... parts).
    Code:
    mkDecreasing []     = ... -- for an empty list
    mkDecreasing (x:xs) = mkDecreasing' x xs
    
    mkDecreasing' x [] = ... -- base case for a recursive call to mkDecreasing'
    mkDecreasing' x (y:ys)
        | ... = ...
        | ... = ...
    Trinithis

  7. #27
    Join Date
    Jun 2008
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Logic Gates In Haskell

    Hi All,

    I am trying to implement the 6 basic logic gates as functions in haskell.

    I have so far managed to get an AND, OR gate to work but i am struggling with the others.

    Can anyone point me in the direction of some useful websites that could help me with this.

    Also how would you implement "not equal to" i thought it would be the following but it did not work.

    > notgate :: Bool -> Bool
    > notgate a = /=a -- a is not equal to a

  8. #28
    Join Date
    May 2007
    Location
    USA
    Posts
    373
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    Code:
    not :: Bool -> Bool
    not True  = False
    not False = True
    p XOR q = (p OR q) AND (NOT (p AND q))
    p NAND q = NOT (p AND q)
    p NOR q = NOT (p AND q)
    Trinithis

  9. #29
    Join Date
    Jun 2008
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the advice, can you confirm if i have coded the following correctly.

    > nand :: Bool -> Bool -> Bool
    > nand a b = not (a and b)

    > nor :: Bool -> Bool -> Bool
    > nor a b = not (a and b)

    > xor :: Bool -> Bool -> Bool
    > xor a b = (a or b) and (not (a and b))

    Thanks

  10. #30
    Join Date
    May 2007
    Location
    USA
    Posts
    373
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    To make non-infix functions infix (aka, any non-operators), you need to surround them with backquotes (`).

    Code:
    nand :: Bool -> Bool -> Bool
    nand a b = not (a `and` b)
    
    nor :: Bool -> Bool -> Bool
    nor a b = not (a `and` b)
    	
    xor :: Bool -> Bool -> Bool
    xor a b = (a `or` b) `and` (not (a `and` b))
    Trinithis

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
  •