I'm having trouble with this function, i need it to give the binary form of a number as a list of 4 elemnts ( just from 0 to 15) so for example for the input 0 it should give me [0,0,0,0], 3 : [0,0,1,1] , 15 [1,1,1,1] so that's what i did
bin 0 x = []
bin n x = (mod x 2) : (bin (n-1) (div x 2))
It gives the result in backwards and this :
bin 0 x = []
bin n x = (bin (n-1) (div x 2)) ++ (mod x 2)
don't work, when compiling it doesn't show an error, but when i enter for example bin 4 1 it shows :
"No instance fo ( Integral [t0]) arising from a use of 'it'
In a stmt of an interactive GHCi command : print it "
I can't figure out what to do, any help will be appreciated
mod x 2is and what it should be if you use it with(++)(hint try to use those square brackets)