-2

I have

cubicQ a b c = ((3*a*c) - b**2)/(9 * (a**2))

I need to get the value of "a" out of that so I can use it in another function, without having to pass it as an argument in that other function. The function I need to use it in is below:

cubicRealSolution q r s t = if p < 0 then error "NaN" else (s + t) - ((b)/(3*(a)))
3
  • 1
    This looks like an (almost) complete duplicate of the question you asked two minutes ago stackoverflow.com/questions/52484370/… Commented Sep 24, 2018 at 17:22
  • What do you think the values of a and b would be? You haven't called cubicQ at all, and whatever values you would use in such a call are the values you would use in cubicRealSolution in the first place. Commented Sep 24, 2018 at 17:25
  • @chepner: in the linked question, the OP defines a q, etc., but does not really makes a "function application". Commented Sep 24, 2018 at 17:31

2 Answers 2

5

Sorry, it's not possible. If you want a function to have access to a value, you must pass that value to the function (and it must be prepared to accept it).

Sign up to request clarification or add additional context in comments.

1 Comment

You can wrap a function inside another one using the where keyword. The wrapped function will have access to all the parameters from the function it is wrapped in. So not impossible although it depends on the situation.
0

Altough this won't work we'll present you this to show the idea. In Haskell you can write

cubicQ a b c = ((3*a*c) - b**2)/(9 * (a**2))

    where

    cubicRealSolution q r s t = if p < 0 then error "NaN" else (s + t) - ((b)/(3*(a)))

The trick is to use the where keyword. Because cubicRealSolution is wrapped inside cubicQ it can have access to its arguments a, b and c without the need to pass them.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.