How to call a function within another function?

Asked

Viewed 93 times

1

I’m doing an activity, and the activity asks to call a function within another function, how can I do that?

2.10 Write a function that returns the value of a high number to the fourth power. This function must make use of another one that calculates the square of any number.

Could just do:

module Fe02 exposing (..)

import Html

funcExp x = x^4

main = Html.text (String.fromFloat (funcExp 2))

So he would give me as a result through server localhost: 16

1 answer

0


Just call one function from the other:

exp2 x = x^2
exp4 x = exp2 (exp2 x)

So for example:

$ elm repl
> exp2 x = x^2
<function> : number -> number
> exp4 x = exp2 (exp2 x)
<function> : number -> number
> exp4 3
81 : number
  • Thank you very much ! Your reply was perfect and succinct friend. Grateful !!!!

  • @Fehlberg, I’m glad I could help. Hug.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.