• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 03:33
CEST 09:33
KST 16:33
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
[ASL22] Ro24 Preview: Summer's End9Serral wins HomeStory Cup 2915Serral wins Maestros of the Game 244ByuL, and the Limitations of Standard Play3Team Liquid Map Contest #22: Results and Winners7
Community News
Weekly Cups (August 10-16): SHIN doubles2GSTL Returns in 2026!45Weekly Cups (Aug 3-9): Protoss get shut out7RSL goes to London! 2026 Offline Finals Nov 21-2212Weekly Cups (July 27-Aug 2): SHIN's big week0
StarCraft 2
General
Geoff 'iNcontroL' Robinson has passed away SC4ALL II: SC2 Player Announcement 6/8 - Maru GSTL Returns in 2026! Balance hotfix patch 5.0.16b (July 16) Serral wins Maestros of the Game 2
Tourneys
PIG STY FESTIVAL 8.0! (13 - 23 August) WORTEX 2026 - Hungarian SC2 Finals Budapest Sparkling Tuna Cup - Weekly Open Tournament SC2 AI Tournament 2026 Fall 2026 GSTL Announcement
Strategy
[G] Having the right mentality to improve
Custom Maps
Nexus Wars 2021 GUIDE [M] (2) Industrial Park
External Content
The PondCast: SC2 News & Results Mutation # 539 Thunder Dome Mutation # 538 Media Blackout Mutation # 537 Hostile Territory
Brood War
General
Replay Review Process - What do you do? Pros React To: First 'Fastest' Map in ASL History BW General Discussion [Personal Project Share] Terran Defense v0.60 ASL22 General Discussion
Tourneys
[ASL22] Ro24 Group C Small VOD Thread 2.0 Toronto invitational lan 22 august [ASL22] Ro24 Group A
Strategy
Odyssey Mineral Stack Saturation Fighting Spirit mining rates Any training maps people recommend? Simple Questions, Simple Answers
Other Games
General Games
Nintendo Switch Thread General RTS Discussion Thread Anyone here play Quakeworld back in the day? Stormgate/Frost Giant Megathread EVE Corporation
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
[TL LoL EUW IHs] Teemo shall perish TSM pausing esports and CLG Dead
Heroes of the Storm
Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
TL Mafia Power Rank TL Mafia Community Thread NeO.D_StephenKing vs This Guy From 1 Million Dance
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Canadian Politics Mega-thread Dating: How's your luck? Artificial Intelligence Thread
Fan Clubs
The Creator Fan Club MarineLorD Fan Club The ShoWTimE Fan Club
Media & Entertainment
Movie Discussion! Anime Discussion Thread
Sports
Football (Soccer) Thread MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023 NBA General Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread Simple Questions Simple Answers FPS when play League Of Legend on laptop
TL Community
The Automated Ban List Northern Ireland Global Starcraft
Blogs
Young Players Exit Esports E…
TrAiDoS
LOCKPICKING NOOB
LUCKY_NOOB
Cathedral Of CS And NY pizza a…
FuDDx
Please support my new stand…
Peanutsc
Customize Sidebar...

Website Feedback

Closed Threads



Active: 5792 users

The Big Programming Thread - Page 76

Forum Index > General Forum
Post a Reply
Prev 1 74 75 76 77 78 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Frigo
Profile Joined August 2009
Hungary1023 Posts
Last Edited: 2011-09-05 13:05:57
September 05 2011 13:04 GMT
#1501
It's a bit of misnomer, it returns a T& reference to the stored object (or throws an exception if the pointer is null). Both operations are on references. Naming is kinda taken from std:: reference_wrapper.

I think it would be wiser to implement it the second way, that only the reference wrapper gets modified. Less headaches with immutable types, threads, unintended consequences.

However, operator + might not return T. Damn. This can complicate things in the second case, with the plain operator +. However in that case I am not obligated to return ref<T> in the proxy. Only the += is problematic since I need to return ref<T>&.

I'll get some sleep over this, hopefully I will come up with a satisfying solution.
http://www.fimfiction.net/user/Treasure_Chest
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
September 05 2011 13:33 GMT
#1502
Basically, if operator overloading is used, anything can happen.

The innocent line
a += 1;
could be an overloaded += operator that initiates nuclear warfare.

Also, the lines
a += 1
could increase a by 1 while
a = a + 1
could decrease a by 10.

This is one of the reasons why java removed operator overloading completely (I don't agree with that decision, but it wasn't totally unreasonable).

If you use operator overloading or use classes that do it, always read the documentation (or in case of the usual lack of it, the code). Otherwise there is no way to really know what will happen. Avoid it as much as possible unless the benefits are far greater than the possible pitfalls for this specific scenario.
EscPlan9
Profile Blog Joined December 2006
United States2777 Posts
Last Edited: 2011-09-05 14:06:55
September 05 2011 13:53 GMT
#1503
On September 03 2011 09:16 Neshapotamus wrote:
EscPlan9, I dont understand your post at all. First off, if you have a WSDL, cant you generate a webservice proxy and use strongly typed object. If that approach doesnt work out and sounds like your getting XML, do you have the XSD for the XML. That way, you can serialize and deserialize the XML into a object. If you dont want to do it that way, can't you use LINQ to XML to and create a annonoymous object with the name for the property you would want.

Maybe, an example of what your trying to do and I can be more clear on taking the best approach.


Fair enough. I have no prior experience with WSDLs - I've just been working with them as if they are XML files. So to be frank, I do not understand the majority of your post either.

The previous developer (no longer with the company) used SvcUtil on the WSDL to generate the client proxy. I originally was tackling the problem through straight XML parsing methods, most recently XPATH. But I figure I really shouldn't be reinventing the wheel when he already figured out a reliable way of parsing the WSDL for the important information he needs. I just know going through his code gives me major headaches trying to understand what he's doing in the sections (no documentation, no comments, code works but is ugly as hell), but I digress...

I'll look into finding the schema (XSD) for the WSDLs. Though I do not yet understand what I should be getting from serializing/deserializing the XMLs (zero experience with that), or how to make use of that information.

As for the last point, I haven't touched LINQ yet. I know SQL and it seems fairly similar in syntax.

The current plan going forward:
1) Take more time to understand how SvcUtil was used on the WSDLs previously.
2) Take more time for planning and design once I understand the organization of the information returned from the SvcUtil generated client proxy.
3) Create new methods to send that information to the (WIP) GUI frontend and generate the tree structure.

A simplified dummy WSDL I created (from the top of my head while at home) that's similar to the WSDLs being analyzed:

<wsdlMe>
<complexType name="Create">
<element name="Items" type="tns:Items" maxOccurs="unbounded"></element>
<element name="Username" type="string"></element>
</complexType>

<complexType name="Items">
<element name="Description" type="string"></element>
<element name="Quantity" type="int"></element>
<element name="Price" type="decimal"></element>
</complexType>

<complexType name="CreateResponse">
<element name="Errors" type="tns:Errors" maxOccurs="unbounded"></element>
</complexType>

<complexType name="Errors">
<element name="Description" type="string"></element>
</complexType>

<complexType name="Finish">
<element name="Time" type="datetime"></element>
</complexType>

<complexType name="FinishResponse">
<element name="Errors" type="tns:Errors" maxOccurs="unbounded"></element>
</complexType>

<messages>
<message name="CreateMsgIn" type="tns:Create"></message>
<message name="CreateMsgOut" type="tns:CreateResponse"></message>
<message name="FinishMsgIn" type="tns:Finish"></message>
<message name="FinishMsgOut" type="tns:FinishResponse"></message>
</messages>

<portType>
<operations>
<operation name="Create" type="tns:CreateMsg"></operation>
<operation name="Finish" type="tns:FinishMsg"></operation>
</operations>
</portType>
</wsdlMe>


The QA tester selects the operation they want to create a test case for. Then the WSDL is parsed (portType/operations/operation) to create the tree structure for the user. So they would see something like

(operation selected is Create)
Create
--CreateMsg
----CreateMsgIn
------Create
--------Items
-----------Description
-----------Quantity
-----------Price
--------Username
----CreateMsgOut

... etc

I've been experimenting with using a Dictionary <string, TreeNode> to hold the information on the tree structure.
Key = child-node-name(string)
Value = parent-node (treenode)

So then when adding a treenode, it's something like

// create new node
TreeNode newNode = new TreeNode(childNodeName);
// get parent node
TreeNode prevNode = dictionary[parentNodeName];
// add child to parent node within tree
prevNode.Nodes.Add(newNode);


I'm pretty stressed that I've wasted a lot of time due to my inexperience here. Thankfully it isn't a high priority at the company? Either way, I've certainly come to appreciate taking more time for designing and planning ahead of time before coding.

(This post was more made to clarify what I'm working on, than to specifically ask questions. Feel free to comment on whatever anyways)
Undefeated TL Tecmo Super Bowl League Champion
pettter
Profile Joined December 2009
Sweden1032 Posts
September 05 2011 14:01 GMT
#1504
Actually, operator overloading, used correctly, is more obvious and less prone to errors than .plus() shenanigans, due to having a well-defined order of precedence without resorting to masses of parentheses. Still, as many (most?) advanced features of C++, it can be horribly, horribly misused as well.

A couple of really hairy combination is a) the combination of multiple inheritance and operator overloading and b) the combination of dynamic typing and operator overloading. Having well-defined types of your variables is absolutely crucial to proper usage of operator overloading.

As for the current problem, the second variant would seem more reasonable, but keep in mind that users may have selected x += y as opposed to x = x + y precisely because they want to change x the object, not x the reference. See [section 13.9 here for example.

It mostly comes down to: comment your damn code, and use const liberally to demonstrate which values change and which do not.
Frigo
Profile Joined August 2009
Hungary1023 Posts
September 05 2011 21:00 GMT
#1505
On September 05 2011 22:33 Morfildur wrote:
This is one of the reasons why java removed operator overloading completely (I don't agree with that decision, but it wasn't totally unreasonable).

Yeah, there are a few heavy abuses of operator overloading but that's no reason to forbid them completely. They are vital to numerical calculations (just as custom value types but that's another story...). They have well defined precedence and can greatly simplify expressions and make them much more transparent. Even if they don't allow full overloading, operators could be aliases for member functions, for example x + y could simply call x.add(y). I believe there is a Java precompiler that does such.

A method can be just as bad as an operator. Undocumented, in violation of contract, malicious. The common reasoning against operators can be applied to methods as well: an add() method might not have anything to do with addition, it could call launchNuclearMissile() just as easily as an operator. They should be treated like methods, with the same scrutiny applied to them. Complete with firing the programmer who abuses operators

If you use operator overloading or use classes that do it, always read the documentation (or in case of the usual lack of it, the code). Otherwise there is no way to really know what will happen. Avoid it as much as possible unless the benefits are far greater than the possible pitfalls for this specific scenario.

Yup, that's the problem here. I do not have a definite class to just look at how it implements operators. Both binary and compound assignment operators might return T, T*, T&, const T& or even a completely unrelated type. The best approach in my case would be to limit the return types to a few correct cases, and use partial template specialization to override this best-guess behavior when it can't model a case properly.
http://www.fimfiction.net/user/Treasure_Chest
0x64
Profile Blog Joined September 2002
Finland4635 Posts
September 05 2011 21:36 GMT
#1506
today I run into a very strange bug with a java midlet app.
I have a base class A and two derived class of A, say B and C.

the problem was with constructor.

A(int n) {
foo = new Plop[n]
}

B() {
super(10);
initFoos();
}

C() {
super(12);
initFoos();
}

----
Now the thing is when I would call initFoos for C, it would crash with out of bound after 10 elements on one device. And work properly on another device...
Just wondering if someone really experienced have deeper knowledge of possible ambiguities.
I have 10 years of work in the field, so I know better not to blame anything else than my code (in this case one of my workers.. ).
We did a work around but I'm not happy about that.
Dump of assembler code from 0xffffffec to 0x64: End of assembler dump.
Frigo
Profile Joined August 2009
Hungary1023 Posts
Last Edited: 2011-09-05 21:56:50
September 05 2011 21:42 GMT
#1507
From the sound of it, C.initFoos() does not give a flying fuck about foo.length (or even modifies foo).

Give us more code, it is difficult to tell the problem from a few lines.
http://www.fimfiction.net/user/Treasure_Chest
Neshapotamus
Profile Blog Joined May 2006
United States163 Posts
Last Edited: 2011-09-06 07:16:37
September 06 2011 07:11 GMT
#1508
Hey EscPlan9,

Seems like you need parse an XML file (in your case a WSDL) and get relevant information from it.

I dont really understand what WIP is but I am assuming its your front end (GUI) which has some type of tree control which can parse an object.

Here is my plan on how I would tackle your situation:
http://schemas.xmlsoap.org/wsdl/ contains the XSD for any WSDL.
Save your xsd

Use visual studio tools to create a class out of the XSD as follows:
xsd.exe [fileName].xsd /c <--cmd line tool (this creates a C# class)

The xsd tool complained about "...", I needed to remove the "..." from the xsd to create the C# class

Add this class to your project.


Write this method as follows:
public object XmlToObject(Type type, string fileName)
{
XmlSerializer ser = new XmlSerializer(type);
FileStream myFileStream = new FileStream(fileName, FileMode.Open);
object obj = ser.Deserialize(myFileStream);
return obj;
}

Now you have your XML(WSDL) as a strong typed object instead of XML. You wont need to parse XML and make references to any xml methods.

You need to convert this object into a Model that you want to send out. I would create a model class and just grab the information you need from the deserialized object.

Have another methods that would create your model(deserialized object) with your tree structure which you would send to your front end.

PM me if this is confusing in any way or I didn't understand you correctly.

Frigo
Profile Joined August 2009
Hungary1023 Posts
September 06 2011 16:00 GMT
#1509
I've got a dilemma about a design choice in my pointer / reference wrapper, the insight of an outsider would be welcome.

Should I proxy operator == and != to the underlying class, just as I do in the case of other operators, or should I use them for pointer comparison instead? Or perhaps both, the latter for pointers, references, rvalue references, reference wrappers, and the former for everything else? Though it sounds kinda dangerous to have two different semantics for a single operator.

I already have an "is" member function for pointer comparison, but it is kinda ugly. For example
ref<int> x = 1;
ref<int> xcopy = x;
ref<int> y = 2;
cout << x.is(xcopy) << endl;
cout << x.is(y) << endl;
cout << x.is(null) << endl;


Perhaps I could define an "is" macro with some trick so the following is possible
cout << x is xcopy << endl;
cout << x is y << endl;
cout << x is null << endl;


For reference, operator = is NOT proxied to the underlying class, it just copies the address where it can. If the user wants assignment he uses
ref<SomeClass> x = new SomeClass(...);
ref<SomeClass> y = new SomeClass(...);
x.get() = y.get();

http://www.fimfiction.net/user/Treasure_Chest
mmp
Profile Blog Joined April 2009
United States2130 Posts
Last Edited: 2011-09-07 15:22:02
September 07 2011 13:53 GMT
#1510
Challenge: Write a function A in your language of choice that takes an object argument O and adds a new function B to O defined as follows: given a function argument C, B sets every other function D in O (exclude B) in the object equal to the given function C applied to the original function D (the return value of C(D) is a function, of course).

Solution (javascript):
+ Show Spoiler +

A = function(O) {
var modified = new Array();
for (var D in O) {
if (!Object.isFunction(O[D])) continue;
modified.push(D);
};
O.B = function(C) {
modified.each(function(D){
O[D] = C(O[D]);
});
return O;
};
return O;
}


I wrote something like this today as part of a functional modifier stack. So you declare A(O) to make an O with extensible methods. You can repeatedly stack functions by repeatedly calling O.B(C) to convert every D into C(D), C(C(D)), C(C(C(D))).... Here is a video of what a modifier stack looks like in Blender to get an idea of how useful this can be.
I (λ (foo) (and (<3 foo) ( T_T foo) (RAGE foo) )) Starcraft
Frigo
Profile Joined August 2009
Hungary1023 Posts
Last Edited: 2011-09-07 16:56:14
September 07 2011 14:08 GMT
#1511
So you are essentially doing an O.D ∘ C composition for every D method of O, where C is a function.

That is not possible in C++ due to lack of type inspection. Even with a wrapper class like mine, you can not proxy methods with arbitrary name, so composition of all methods is not possible. Especially not dynamically.

But I believe you can make a class template A that in its constructor accepts o and c objects (of which are instances of template parameters O and C, an object and a functor respectively), and proxies all operators and a given set of methods of O that are known beforehand. Still no dynamically though.

Edit:

Yup, it is possible statically for a limited set of methods and operators, see this example for operator ():

#include <iostream>
#include <functional>
#include <utility>

using namespace std;

template <class O, class C>
class A
{

public:

A (O& o2, C& c2) :
o (o2),
c (c2)
{}

template <class... Args>
decltype(std::declval<O&&>()(std::declval<C&&>()(std::declval<Args&&>()...))) operator () (Args&&... args)
{
return o(c(std::forward<Args&&>(args)...));
}

protected:

O& o;
C& c;

};



class O
{

public:

int operator () (int x)
{
return 2 * x;
}

};

class C
{

public:

int operator () (int x)
{
return x + 1;
}

};


int main (int argc, char* argv[])
{
O o;
C c;
A<O, C> a(o, c);

cout << a(1) << endl;
cout << a(10) << endl;
}

http://www.fimfiction.net/user/Treasure_Chest
mmp
Profile Blog Joined April 2009
United States2130 Posts
September 07 2011 15:31 GMT
#1512
Impressive, Frigo. I was hoping someone would post a C/C++ solution.
I (λ (foo) (and (<3 foo) ( T_T foo) (RAGE foo) )) Starcraft
icystorage
Profile Blog Joined November 2008
Jollibee19350 Posts
September 08 2011 12:57 GMT
#1513
i would like to thank the people who helped my on my last problem, yes it was working properly, my bad D:

i have another problem :< im stuck and i hope you guys can help
it compiles correctly but gives an error when i use it


> myprod n m = if m == 0 then 0 else (myprod n (m - 1)) + n

> myprod2 n m = if n == 1 then m else if n mod 2 == 1 then (myprod (n div 2) (m + m)) + m else (myprod (n div 2) (m + m))



this is a multiplication function.
myprod is my old fcn, its very slow so i tried improving it by using binary multiplication.

myprod2 is what i have come up but it returns an error even though it compiles properly, the error is

no instance for (num ((a0->a0->a0->a10->a20)) arising from the literal '5'
possible fix: add an instance declaration for (num ((a0->a0->a0->a10->a20))

and my problem is i dont know how to fix it =/
LiquidDota StaffAre you ready for a Miracle-? We are! The International 2017 Champions!
Kambing
Profile Joined May 2010
United States1176 Posts
Last Edited: 2011-09-08 15:20:11
September 08 2011 14:39 GMT
#1514
On September 08 2011 21:57 icystorage wrote:
i would like to thank the people who helped my on my last problem, yes it was working properly, my bad D:

i have another problem :< im stuck and i hope you guys can help
it compiles correctly but gives an error when i use it


> myprod n m = if m == 0 then 0 else (myprod n (m - 1)) + n

> myprod2 n m = if n == 1 then m else if n mod 2 == 1 then (myprod (n div 2) (m + m)) + m else (myprod (n div 2) (m + m))



this is a multiplication function.
myprod is my old fcn, its very slow so i tried improving it by using binary multiplication.

myprod2 is what i have come up but it returns an error even though it compiles properly, the error is

no instance for (num ((a0->a0->a0->a10->a20)) arising from the literal '5'
possible fix: add an instance declaration for (num ((a0->a0->a0->a10->a20))

and my problem is i dont know how to fix it =/


That's a compiler error actually. The problem is that when you use standard function names as infix operators, you need to encase them in backquotes, e.g., n `div` 2 is equivalent to div 2 n. Writing 1 div 2 is in effect saying "apply the div function (of type Integral a => a -> a -> a) to the constant 1 (of type Num a => a) and then take the result and apply the constant 2". Clearly 1 is not a function so the whole thing fails to type check.

EDIT: because of typeclasses, Haskell can give 1 div 2 a type

1 div 2 :: (Num a1, Num ((a -> a -> a) -> a1 -> t), Integral a) => t


Because it tries to unify the type of 1 with a function type that can take the div function as an argument. However, it fails when the typechecker tries to find an instantiation of the type variable a that satisfies the constraint. Hence the nasty compiler error that you see.
FranzP
Profile Joined November 2010
France270 Posts
Last Edited: 2011-09-08 15:13:08
September 08 2011 14:53 GMT
#1515
@Frigo I'm working with java so there is this kind of design i.e. == compares ref and .equals(x) method compares content.

What I don't like with this design is that I usually use object comparison more often than ref comparison. And I feel like the equals method clutters my code.

It's just about taste but if I were you I would use == to compare the referenced object and another method to compare reference. That's just my feelings using == and .equals()
"Cyberhacking is kind of like masturbation I guess, all countries do it but nobody actually talks about it. China just was accidentally doing it with the door wide open." Newbistic
Nisani201
Profile Joined September 2010
United States1400 Posts
September 08 2011 15:17 GMT
#1516
w3schools should not be included in the OP; read this for more info.
Enjoy your day.
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
September 08 2011 15:23 GMT
#1517
On September 08 2011 23:53 FranzP wrote:
@Frigo I'm working with java so there is this kind of design i.e. == compares ref and .equals(x) method compares content.

What I don't like with this design is that I usually use object comparison more often than ref comparison. And I feel like the equals method clutters my code.

It's just about taste but if I were you I would use == to compare the referenced object and another method to compare reference. That's just my feelings using == and .equals()


.equals() also adds some problems to the language like x.equals(y); that throws an exception if x is null, == doesn't have that problem. That leads to wierd stuff like "somestring".equals(x); which is... not quite logical or intuitive.
Kambing
Profile Joined May 2010
United States1176 Posts
September 08 2011 16:36 GMT
#1518
On September 09 2011 00:23 Morfildur wrote:
Show nested quote +
On September 08 2011 23:53 FranzP wrote:
@Frigo I'm working with java so there is this kind of design i.e. == compares ref and .equals(x) method compares content.

What I don't like with this design is that I usually use object comparison more often than ref comparison. And I feel like the equals method clutters my code.

It's just about taste but if I were you I would use == to compare the referenced object and another method to compare reference. That's just my feelings using == and .equals()


.equals() also adds some problems to the language like x.equals(y); that throws an exception if x is null, == doesn't have that problem. That leads to wierd stuff like "somestring".equals(x); which is... not quite logical or intuitive.


.equals itself is a nasty corner of the language due to the difference between primitive (value) and reference types. However, being able to call methods on any object, i.e., "hello".equals(x), should be expected in an object-oriented language where "everything is an object". It ought to be considered weird that you aren't able to call methods on primitive data (in Java at least, C# automatically boxes primitives so that you can do this --- at the cost of the actual boxing operation).
icystorage
Profile Blog Joined November 2008
Jollibee19350 Posts
September 08 2011 18:37 GMT
#1519
On September 08 2011 23:39 Kambing wrote:
Show nested quote +
On September 08 2011 21:57 icystorage wrote:
i would like to thank the people who helped my on my last problem, yes it was working properly, my bad D:

i have another problem :< im stuck and i hope you guys can help
it compiles correctly but gives an error when i use it


> myprod n m = if m == 0 then 0 else (myprod n (m - 1)) + n

> myprod2 n m = if n == 1 then m else if n mod 2 == 1 then (myprod (n div 2) (m + m)) + m else (myprod (n div 2) (m + m))



this is a multiplication function.
myprod is my old fcn, its very slow so i tried improving it by using binary multiplication.

myprod2 is what i have come up but it returns an error even though it compiles properly, the error is

no instance for (num ((a0->a0->a0->a10->a20)) arising from the literal '5'
possible fix: add an instance declaration for (num ((a0->a0->a0->a10->a20))

and my problem is i dont know how to fix it =/


That's a compiler error actually. The problem is that when you use standard function names as infix operators, you need to encase them in backquotes, e.g., n `div` 2 is equivalent to div 2 n. Writing 1 div 2 is in effect saying "apply the div function (of type Integral a => a -> a -> a) to the constant 1 (of type Num a => a) and then take the result and apply the constant 2". Clearly 1 is not a function so the whole thing fails to type check.

EDIT: because of typeclasses, Haskell can give 1 div 2 a type

1 div 2 :: (Num a1, Num ((a -> a -> a) -> a1 -> t), Integral a) => t


Because it tries to unify the type of 1 with a function type that can take the div function as an argument. However, it fails when the typechecker tries to find an instantiation of the type variable a that satisfies the constraint. Hence the nasty compiler error that you see.

*holds hand* thank you my friend... thank you... how could i be so stupid ._.
LiquidDota StaffAre you ready for a Miracle-? We are! The International 2017 Champions!
Frigo
Profile Joined August 2009
Hungary1023 Posts
September 08 2011 19:20 GMT
#1520
On September 08 2011 23:53 FranzP wrote:
@Frigo I'm working with java so there is this kind of design i.e. == compares ref and .equals(x) method compares content.

What I don't like with this design is that I usually use object comparison more often than ref comparison. And I feel like the equals method clutters my code.

It's just about taste but if I were you I would use == to compare the referenced object and another method to compare reference. That's just my feelings using == and .equals()


Thank you for your feedback. I asked my friend as well and concluded that indeed this is the correct approach.

Object comparison is done with == and !=, pointer comparison is done with an "is" macro that is defined as:
#define is .getPointer() ==


It seems to be working pretty well, it handles pointer comparison between reference wrappers as well, due to implicit conversion to pointer.
http://www.fimfiction.net/user/Treasure_Chest
Prev 1 74 75 76 77 78 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 2h 28m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
BRAT_OK 16
MindelVK 9
StarCraft: Brood War
Shuttle 3951
actioN 417
Mind 51
Bale 39
Noble 18
ZergMaN 14
Dota 2
The International138542
Gorgc8058
singsing2416
League of Legends
JimRising 634
Super Smash Bros
Mew2King61
Other Games
summit1g7841
WinterStarcraft510
Happy251
Sick147
RuFF_SC261
Organizations
Other Games
gamesdonequick524
[ Show 10 non-featured ]
StarCraft 2
• Berry_CruncH438
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• Migwel
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Lourlo1332
Upcoming Events
Sparkling Tuna Cup
2h 28m
PiG Sty Festival
4h 28m
Solar vs Reynor
Serral vs TBD
OSC
8h 28m
Afreeca Starleague
1d 2h
hero vs ggaemo
Larva vs Mong
The Patches Monday
1d 8h
Afreeca Starleague
2 days
Soulkey vs PianO
JyJ vs sSak
GSL
2 days
PiGosaur Cup
2 days
Replay Cast
2 days
Afreeca Starleague
3 days
Mini vs Calm
Queen vs EffOrt
[ Show More ]
Replay Cast
3 days
The PondCast
4 days
IntoTheTV X SOOP
5 days
GSL
6 days
Replay Cast
6 days
Liquipedia Results

Completed

Escore Tournament S3: W8
CranK Gathers Season 4: BW vs SC2 Team League
Eternal Conflict S2 Finale

Ongoing

KCM Race Survival 2026 Season 3
K-JUNGMAN
ASL Season 22
Super Anchor Qualifying S3
CSL Season 22: Qualifier 1
RSL Revival: Season 6
PiG Sty Festival 8.0
META DYMY #4
Esports World Cup 2026
Esports World Cup 2026: LCQ
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026

Upcoming

CSL Season 22: Qualifier 2
CSL 2026 AUTUMN (S22)
Acropolis #5
Acropolis #5 - TRS
Blizzard Classic Cup 2026
Acropolis #5 - GSA
Acropolis #5 - GSB
HSC XXX
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
RSL Offline Finals
Calamity Invitational
Big Dog Cup 2026 Div 1
IEM Beijing 2026
Stake Ranked Episode 5
PGL Masters Bucharest 2026
Thunderpick World Champ. '26
ESL Pro League Season 24
Stake Ranked Episode 4
1win Private Club #1
Logitech G Play Connect 2026
SL StarSeries Fall 2026
FISSURE Playground #3
BLAST Open Fall 2026
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.