Jump to content

Need Haskell help

- - - - -

  • Please log in to reply
2 replies to this topic

#1
djzingo

djzingo

    Newbie

  • Members
  • Pip
  • 3 posts
I have the following code


data Hand = Empty | Add Card Hand

          deriving (Eq, Show)



(<+) :: Hand →  Hand →  Hand

(<+) Empty hand2 = hand2

(<+) hand1 Empty = hand1

(<+) (Add card hand1) hand2 =  "concatenate hand1 with hand2"

So how can I simply and syntac correctly concatenate hand1 with hand 2?

#2
djzingo

djzingo

    Newbie

  • Members
  • Pip
  • 3 posts
Never mind the first problem, I have a new One.
The following code below

blanks :: Sudoku →  Pos
blanks (Sudoku sud) = blnks (concat sud `zip`
      [(x, y) | x ←  [0..8], y ←  [0..8]])

blnks []                        = error "blnks [] error"
blnks ((x,y):xs) | x ≡ Nothing = y
                | otherwise    = blnks xs

This returns the first element.
Hovever I would like the function to act like this

blanks :: Sudoku →  [Pos]

In other words i wold like to return a list instead.
How can the above code be editet to achieve this?

#3
so1i

so1i

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 312 posts
I've just started Haskell, so I might not be much help, but find this quite interesting. Let me get this right... you want to put in something of type Sudoku into the function, and return a list of all of the positions of the blanks within it?

I did some looking around and found this link. There seems to be quite a few examples of this on the web, and this one seemed to make most sense to me (obviously taking into account the error he made and the fixed version). I think you could probably map this to your particular sudoku problem. Good luck!

EDIT: This post also brings about something I have been thinking about since I've started being taught Java in the past month or so. How come there is no section for it here at Codecall? Unless I'm being lied to there is quite the community for it, and while I know codecall can't possibly cater for all languages, it seems like quite an interesting one to have a section for (also for personal benefit, it would really help! - I'm actually having a much harder time that I thought I would grasping it's functional ways :D).
My Company - My Homepage - My Twitter - My Google+ - My LinkedIn

"Things don’t have to change the world to be important.” - Steve Jobs




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users