Difference between revisions of "Talk:99 questions/1 to 10"

From HaskellWiki
Jump to navigation Jump to search
 
Line 4: Line 4:
   
 
[[User:Chrycheng|Chrycheng]] 12:02, 12 September 2007 (UTC)
 
[[User:Chrycheng|Chrycheng]] 12:02, 12 September 2007 (UTC)
  +
  +
I think the answer to problem 6 is kind of "cheating". I think something like this would be a nice alternate solutions:
  +
  +
<haskell>
  +
isPalindrome :: Eq (a) => [a] -> Bool
  +
isPalindrome [] = True
  +
isPalindrome [x] = True
  +
isPalindrome (x:xs) = x == last xs && isPalindrome (init xs)
  +
</haskell>
  +
  +
[[User:Michael|Michael]] 16:40, 17 January 2008 (UTC)

Revision as of 16:40, 17 January 2008

Does the problem 1 example need correction?

The problem refers us to last as a Prelude function providing the same functionality. However, last has type [a] -> a which differs from the Lisp example's type [a] -> [a]. Should we revise the example or should we rephrase the reference to last to highlight the difference?

Chrycheng 12:02, 12 September 2007 (UTC)

I think the answer to problem 6 is kind of "cheating". I think something like this would be a nice alternate solutions:

isPalindrome        :: Eq (a) => [a] -> Bool
isPalindrome []     = True
isPalindrome [x]    = True
isPalindrome (x:xs) = x == last xs && isPalindrome (init xs)

Michael 16:40, 17 January 2008 (UTC)