[Haskell-beginners] Error Message when trying to solve alphametic(SEND + MORE = MONEY)

Sok Ha Chang shaegis at gmail.com
Sun Jan 26 13:26:24 UTC 2014


How stupid I am…
Thank you very much !
Have a nice day. 
Thanks, again. 

Sincerely, S. Chang


2014. 1. 26. 오후 9:24 Matthew Moppett <matthewmoppett at gmail.com> 작성:

> Hi Sok Ha.
> 
> expr    = show send ++ "+" ++ show more ++ "=" show money
> 
> 
> 
>> On Sun, Jan 26, 2014 at 7:16 PM, Sok Ha Chang <shaegis at gmail.com> wrote:
>> Hi.
>> I’m new to Haskell.
>> Use Haskell Platform on MacBook Air.
>> $ ghc --version
>> The Glorious Glasgow Haskell Compilation System, version 7.6.3
>> 
>> I’m try to solve alphametic.
>> SEND + MORE = MONEY
>> 
>> Here is code…
>> ----------------------------------------------------------------------------------------------------------
>> import Data.List
>> 
>> decryp :: [Int] -> String -> String
>> decryp (s:e:n:d:o:r:y:[]) a =
>>        if send + more == money then expr:a else a
>>        where
>>                send    = s * 1000 + e * 100 + n * 10 + d
>>                more    = 1000 + o * 100 + r * 10 + e
>>                money   = 10000 + o * 1000 + n * 100 + e * 10 + y
>>                expr    = show send ++ "+" ++ show more ++ "=" show money
>> 
>> decrypSolver :: [String]
>> decrypSolver =
>>        foldr decryp [] (permutations 7 [0, 2, 3, 4, 5, 6, 7, 8, 9])
>> ----------------------------------------------------------------------------------------------------------
>> 
>> Error Messages is
>> ./decrypSolver.hs: line 10, column 60:
>>  Couldn't match expected type `(a0 -> String) -> Int -> [Char]'
>>              with actual type `[Char]'
>>  The function `"="' is applied to two arguments,
>>  but its type `[Char]' has none
>>  In the second argument of `(++)', namely `"=" show money'
>>  In the second argument of `(++)', namely
>>    `show more ++ "=" show money’
>> ----------------------------------------------------------------------------------------------------------
>> 
>> How can I fix this?
>> 
>> Thank you.
>> 
>> Sincerely, S. Chang
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://www.haskell.org/mailman/listinfo/beginners
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners


More information about the Beginners mailing list