I'm having trouble writing this code that my professor has given me:
Write a function called
digit7
which takes anInt
and returns aBool
saying whether or not 7 is one of the digits. (Hint: useshow
to turn the number into a list of characters.) Usedigit7
to create a function of no parameters calledsquare7
which returns the smallest number whose square contains a 7 as a digit.
The code that I have is:
digit7 l = elem '7' (show l)
This works but, I need the code written in a point-free style. I am also having trouble figuring out the square7
function as well.
For the digit7
function, you can convert your definition to point-free style by using functional composition:
digit7 = (elem '7') . (show)
This is because:
digit7 l
-> ((elem '7') . (show)) l By substitution
-> (elem '7') ((show) l) By definition of (.)
-> elem '7' (show l) By operator precedence
As for the square7
function, I recommend using dropWhile
and head
.