Announcement of the type of function in Haskell



  • I'm trying to move from Prolog to Haskell.

    We've got to make a rhythmical statement.

    I'm writing a recurring program similar to Prolog. Since in the Haskell list, unlike Prolog, all elements shall be of one type, using the type [String]. The arguments for numerical representation should be changed, and the result of the calculation should be reverted to symbolic.

    Compiler's not missing.
    Is there something wrong with the proclamation or is it a methodical error?

    cc :: (String b) => [String] -> b
    cc (a:"*":b:t) = cc(c:t)
        where c=show(read a * read b)
    cc (a:"/":b:t) = cc(c1:t)
        where c1=show(read a / read b)
    cc (a:"-":t)   = show(read a - read(cc t))
    cc (a:"+":t)   = show(read a + read (cc t))
    cc (a:[])      = a
    cc []          = 0
    

    Mistake:

    ERROR file:



  • First start by pointing out what you've got on the job type.

    The erroneous report actually claims that there is no such class String♪ Indeed, String It's not a class, it's just a type of data, a list of symbols. Therefore, the expression (String b) => ... Doesn't make sense.

    Probably. b should have a numerical type, a specific type may be used for starters, for example Double

    Thus, the type of function will be as follows: [String] -> Double

    Then you have a problem with the function not always returning the number, sometimes she returns the line. It's no longer easy to fix, there's a need to make some changes to the logic of the programme.

    You need to reconsider how to deal with such expressions and use more appropriate programming technologies in Haskell.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2