Haskell concat Int -
i having trouble following exercise:
i must make function named adddigit, takes 2 int's, second 1 being between 0 , 9, , return int first int followed second one.
example:
input: adddigit (-123) 4
output: -1234
what have tried following :
adddigit :: int -> int -> int adddigit x y = x ++ y
i doesn't work because ++ keyword works strings, chars , lists (i think), , supposed solved in simple way without changing int's strings or sort of other variables, have no clue @ on how it.
you trying solve problem graphically (thinking of integers strings), want treat numerical problem. positive values, appending digit accomplished following function.
adddigitpositive b = 10 * + b
this unfortunately not work if a < 0
. under circumstances have subtract b
. can incorporate functionality function guards.
adddigit b | < 0 = * 10 - b | otherwise = * 10 + b
Comments
Post a Comment