selectMenu :: Int->IO()
selectMenu num
|(num==1)=convertFromDecimal
|(num==2)=--menu2
|(num==3)=putStrLn("3")
|(num==4)=putStrLn("4")
|(num==5)=putStrLn("5")
convertFromDecimal:: IO()
convertFromDecimal= do
putStrLn("\n\tConvert From Decimal To Binary & Octals \n")
putStrLn("----------------------------------------------------------\n")
putStrLn("Enter 5 decimal numbers [,,] : ")
input<-getLine
let n=(read input)::[Int] -- is this right?
--putStrLn (show n)
let result = convertionTO decToOct n
putStrLn(show result)`
decToOct :: Int -> [Int]
decToOct x = reverse(decToOct' x)
where
decToOct' 0 = []
decToOct' y = let (a,b) = quotRem y 8 in [b] ++ decToOct' a
convertionTO :: (Int -> [Int] -> [Int]) -> [Int] -> [Int]
convertionTO _ [] = []
convertionTO f (x:xs) = f x : convertionTO f xs
I correct those mistakes. I did update the question after correcting those errors. But this time it gives this error
How can i fix this error?
Assignment.hs:49:51:
Couldn't match expected type `[Int] -> [Int]'
with actual type `[Int]'
Expected type: Int -> [Int] -> [Int]
Actual type: Int -> [Int]
In the first argument of `convertionTO', namely `decToOct'
In the expression: convertionTO decToOct n
Assignment.hs:66:25:
Couldn't match expected type `Int'
with actual type `[Int] -> [Int]'
In the return type of a call of `f'
In the first argument of `(:)', namely `f x'
In the expression: f x : convertionTO f xs
(I’m copying the errors here in case you edit the question again.)
The first error
refers to this line of code
conversionTOexpects its first argument to have the typeInt -> [Int] -> [Int], butdecToOctinstead has the typeInt -> [Int].The second error
refers to this line of code
convertionTOproduces an[Int], so the first argument to:must be anInt. Butf xinstead has type[Int] -> [Int].How to fix these?
I’m going to assume that your line 49 is correct, and that the type signature for
convertionTOis wrong. In that case it should beThis doesn’t fix the second error, as
f xnow has type[Int].The problem here is your use of
:.:joins a single element to the start of a list. What you have is two lists that you want to join together. For this, use++.Finally, note that your
convertionTOis in the standard library asconcatMap, which combinesmapwithconcat.