katkitten1

Untitled

Nov 14th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. delete :: Char -> [Char] -> [Char]
  2. delete a as = [ x | x <- as, x /= a]
  3.  
  4. convertToInt n
  5.     | n == 'X'    = 10
  6.     | otherwise   = read [n] :: Integer
  7.  
  8. isbnToList n = do
  9.     let simplify = delete '-' n
  10.     return [convertToInt a | a <- simplify ]
  11.  
  12.  
  13. BUT!!!!
  14.  
  15.  
  16. *Main> isbnToList "3-598-21508-8"
  17. [3,5,9,8,2,1,5,0,8,8]
  18.  
  19. *Main> zipWith (*) [10,9,8,7,6,5,4,3,2,1] [3,5,9,8,2,1,5,0,8,8]
  20. [30,45,72,56,12,5,20,0,16,8]
  21.  
  22. *Main> zipWith (*) [10,9,8,7,6,5,4,3,2,1] $ isbnToList "3-598-21508-8"
  23.  
  24. <interactive>:140:9: error:
  25.     • No instance for (Num [Integer]) arising from a use of ‘*’
  26.     • In the first argument of ‘zipWith’, namely ‘(*)’
  27.       In the expression: zipWith (*) [10, 9, 8, 7, ....]
  28.       In the expression:
  29.         zipWith (*) [10, 9, 8, 7, ....] $ isbnToList "3-598-21508-8"
Advertisement
Add Comment
Please, Sign In to add comment