Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6835641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:15:23+00:00 2026-05-26T23:15:23+00:00

I have two functions: calctvd :: [Perk] -> [Perk] -> Perk -> Double calctvd

  • 0

I have two functions:

calctvd :: [Perk] -> [Perk] -> Perk -> Double
calctvd ps fs p = (fromIntegral(tvn) / fromIntegral(points)) :: Double
    where
        tvn = calctvn ps fs p
        points = length $ [i | i <- perkAndPreqs ps p, i `notElem` fs]

The above function always succeeds in returning the double that I would expect. The important line is the division (fromIntegral(tvn) / fromIntegral(points)). The function calctvn (not shown here) and the variable points are always integers, so fromIntegral() is necessary.

updatetvd :: [Perk] -> [Perk] -> [Perk]
updatetvd [] _ = []
updatetvd ps fs
    --If p is in the list of elements already taken, then do not update it
    | p `elem` fs = [p] ++ updatetvd (tail ps) fs
    --Otherwise, update the tvd value
    | otherwise = [PerkImpl (tvd, school, skill, name, def, preqstr, pref)] ++ updatetvd (tail ps) fs
    where
        p = head ps
        PerkImpl (_, school, skill, name, def, preqstr, pref) = p
        tvd = calctvd ps fs p

Essentially, this second function should just insert the value of the first function into a list. However, it only inserts the numerator of the term (fromIntegral(tvn) / fromIntegral(points)). I proved this by changing that line in calctvd to 3 / fromIntegral(points). With this, calctvd still returned the correctly divided double, whereas updatetvd always inserted a value of 3.0. It is as if Haskell does not evaluate the denominator if calctvd is called from inside updatetvd.

Update 1:

However, it appears that this oddity relies on some complexity in the above two functions. I tried to break it down into a simple example:

testcalctvd :: Double
testcalctvd = fromIntegral(3) / fromIntegral(4) :: Double

testupdatetvd :: Double
testupdatetvd = testcalctvd

However, both testcalctvd and testupdatetvd return the correct 0.75.

Update 2:

Here is an example straight from Terminal, using the test term 3 / fromIntegral(points):

> calctvd initial [] i17
0.6    {This is 3/5, because i17 has 5 points}
> updatetvd initial []
[...3.0...]    {This is just the numerator 3}

Update 3:

Here is the perkAndPreqs function, which is probably the culprit, but I am not sure how much sense it will make:

--Take a perk and return a list of that perk and all of its pre-requisites
perkAndPreqs :: [Perk] -> Perk -> [Perk]
perkAndPreqs _ NULL = []
perkAndPreqs ps p = [p] ++ perkAndPreqs ps preq
    where
        PerkImpl (_, _, _, _, _, preqstring, _) = p
        preq = perkIdentifier preqstring ps
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:15:24+00:00Added an answer on May 26, 2026 at 11:15 pm

    My guess is that when you call calctvd by hand, the p parameter you pass is not also the first element of the ps parameter. But when calctvd is called from updatetvd, p = head ps.

    I cannot be sure, because you’ve shown us neither failing test cases nor the definition of perkAndPreqs (if points is being miscalculated as 1, the clue as to why is likely to be in perkAndPreqs).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have two functions that expect ...rest parameters private function a(...myParams):void { trace(myParams.length);
I have two functions in an ActionScript class, they are: private function loaderCompleteHandler(event:Event):void {
I have two Python functions, both of which take variable arguments in their function
I have two functions here say animation1 and load1 they work like that: function
I have two functions: double fullFingerPrinting(string location1, string location2, int nGrams) double AllSubstrings(string location1,
I have two functions, one which parses all the arguments sent to the function
I have two functions whose execution time I would like to compare: function subject_one()
I have two functions written in VB.NET: 1) The first function (call it GetValues())
I have two functions named ChangeText() & ChangeColor(), the first function called ChangeText who
I have two functions in my js file: function all_opened() { allToggle(true); } function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.