Results 1 to 2 of 2

Thread: Haskell Help

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

    Default Haskell Help

    Hi All,

    I am currently learning haskell and trying to make a small program that defines the following gates: AND,OR,NAND,NOR,NOT,XOR

    so far i have the following code below:

    but for some reason the not function works on its own, but when i put it with the following code below, i get the following error.

    Syntax error in input (unexpected `=`)

    It would be great if someone code have a look and tell me what i have done wrong, Thanks

    Code:
    > and :: Bool -> Bool -> Bool
    > and a b = a&&b
    
    > or :: Bool -> Bool -> Bool
    > or a b = a||b
    
    > not :: Bool -> Bool
    > not True = False
    > not False = True
    
    > 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))

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

    Default

    and, or, and not are already defined in the Prelude. You have to explicitly hide them before defining your own:
    Code:
    > module Main where
    > import Prelude hiding (and, or, not)
    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. The Following User Says Thank You to Twey For This Useful Post:

    DigitalDreams (06-24-2008)

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
  •