Giter Site home page Giter Site logo

Make record names unique about stocks HOT 5 CLOSED

dabcoder avatar dabcoder commented on May 28, 2024
Make record names unique

from stocks.

Comments (5)

dabcoder avatar dabcoder commented on May 28, 2024

Would you have an example of that, as in, how would it work for, say, Quote?

from stocks.

ksallberg avatar ksallberg commented on May 28, 2024

Lets say we want to read the 'companyName' field of the Stats record, like this (from branch bug/no-lookup):

diff --git a/Tests/Main.hs b/Tests/Main.hs
index 9996609..0c185f4 100644
--- a/Tests/Main.hs
+++ b/Tests/Main.hs
@@ -95,3 +81,15 @@ testMultiBatch1 = TestCase
 testMultiBatch2 = TestCase
   (do result <- getBatch ["dps", "fb"] [OHLCQuery, CompanyQuery]
       assertBool "" (result /= Nothing))
+
+
+-- fail
+testCorrectCompanyName = TestCase
+   (do result <- getBatchCompany "aapl" [StatsQuery, NewsQuery, CompanyQuery]
+       assertEqual "" (pickCompanyName result) "Apple Inc.")
+
+pickCompanyName :: Maybe Batch -> String
+pickCompanyName (Just (Batch {stats = st})) = pickCompanyName' st
+
+pickCompanyName' :: Maybe Stats -> String
+pickCompanyName' (Just (Stats {companyName = cname})) = cname

We can't do this, since 'companyName' is not unique:

/Users/kristiansallberg/Documents/stocks/Tests/Main.hs:95:32: error:
    Ambiguous occurrence ‘companyName’
    It could refer to either the field ‘companyName’,
                             imported from ‘Net.Stocks’ at Tests/Main.hs:5:1-17
                          or the field ‘companyName’,
                             imported from ‘Net.Stocks’ at Tests/Main.hs:5:1-17
                          or the field ‘companyName’,
                             imported from ‘Net.Stocks’ at Tests/Main.hs:5:1-17
   |
95 | pickCompanyName' (Just (Stats {companyName = cname})) = cname
   |

So the way I propose to fix this, is to put the data structure definitions in separate modules, so that they can be uniquely accessed. If you don't have some better solution :-)

edit Actually, it works fine if '{-# LANGUAGE DuplicateRecordFields #-}' is added to the files using our library. But it kind of sucks to have to use language extensions just to use this lib

from stocks.

ksallberg avatar ksallberg commented on May 28, 2024

Please see this 693aec3 for what it would look like with my proposal (for Stats). I guess another solution would be to make sure no record fields are duplicate, like "statusCompanyName" in Status

from stocks.

dabcoder avatar dabcoder commented on May 28, 2024

I see, thanks for the detailed explanation.
We can probably go ahead with your proposal, I don't have any other suggestions at this point, thanks for looking into it!

from stocks.

ksallberg avatar ksallberg commented on May 28, 2024

Fixed by factoring out data types to their own haskell modules

from stocks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.