1

hi_copy.hs

waxOn = x
    where 
        z = 7
        y = z + 18
        k = y ^ 2
        x = k * 5

triple  = a
    where 
        a = a * 3 

then load.

ghci> :load hi_copy.hs
[1 of 1] Compiling Main             ( hi_copy.hs, interpreted )
Ok, one module loaded.

then run triple waxOn

<interactive>:122:1: error:
    • Couldn't match expected type ‘Integer -> t’
                  with actual type ‘Integer’
    • The function ‘triple’ is applied to one value argument,
        but its type ‘Integer’ has none
      In the expression: triple waxOn
      In an equation for ‘it’: it = triple waxOn
    • Relevant bindings include it :: t (bound at <interactive>:122:1)

run 3 * waxOn will work. but now I don't how to make triple waxOn working. meta: till now still not learning type in haskell. There maybe other good answers already exists. But I don't understand other people's great answer.

2
  • 2
    triple does not take a parameter. You made an endless recursive function where a is (((((...) * 3) * 3) * 3). Commented Mar 24, 2022 at 16:21
  • 3
    triple x = x * 3. Commented Mar 24, 2022 at 16:22

1 Answer 1

3

Your triple does not take any parameter. It only returns a value, a value that will be the result of endless recursion where a is ((((…) * 3) * 3) * 3).

You should take as input a parameter, so:

triple :: Num a => a -> a
triple a = a * 3

or shorter:

triple :: Num a => a -> a
triple = (3 *)
Sign up to request clarification or add additional context in comments.

2 Comments

triple :: Num a => a -> a after sometime learning will be solved. for now triple a = a * 3 solved my problem.
Strictly speaking, (* 3), since a * 3 == 3 * a isn't guaranteed to be true for all Num a => a :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.