• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 00:55
CEST 06:55
KST 13:55
  • 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
Team TLMC #5 - Finalists & Open Tournaments0[ASL20] Ro16 Preview Pt2: Turbulence10Classic Games #3: Rogue vs Serral at BlizzCon9[ASL20] Ro16 Preview Pt1: Ascent10Maestros of the Game: Week 1/Play-in Preview12
Community News
Weekly Cups (Sept 8-14): herO & MaxPax split cups4WardiTV TL Team Map Contest #5 Tournaments1SC4ALL $6,000 Open LAN in Philadelphia8Weekly Cups (Sept 1-7): MaxPax rebounds & Clem saga continues29LiuLi Cup - September 2025 Tournaments3
StarCraft 2
General
#1: Maru - Greatest Players of All Time Weekly Cups (Sept 8-14): herO & MaxPax split cups Team Liquid Map Contest #21 - Presented by Monster Energy SpeCial on The Tasteless Podcast Team TLMC #5 - Finalists & Open Tournaments
Tourneys
Maestros of The Game—$20k event w/ live finals in Paris SC4ALL $6,000 Open LAN in Philadelphia Sparkling Tuna Cup - Weekly Open Tournament WardiTV TL Team Map Contest #5 Tournaments RSL: Revival, a new crowdfunded tournament series
Strategy
Custom Maps
External Content
Mutation # 491 Night Drive Mutation # 490 Masters of Midnight Mutation # 489 Bannable Offense Mutation # 488 What Goes Around
Brood War
General
[ASL20] Ro16 Preview Pt2: Turbulence BW General Discussion ASL20 General Discussion Diplomacy, Cosmonarchy Edition BGH Auto Balance -> http://bghmmr.eu/
Tourneys
[ASL20] Ro16 Group D [ASL20] Ro16 Group C [Megathread] Daily Proleagues SC4ALL $1,500 Open Bracket LAN
Strategy
Simple Questions, Simple Answers Muta micro map competition Fighting Spirit mining rates [G] Mineral Boosting
Other Games
General Games
Path of Exile Stormgate/Frost Giant Megathread General RTS Discussion Thread Nintendo Switch Thread Borderlands 3
Dota 2
Official 'what is Dota anymore' discussion LiquidDota to reintegrate into TL.net
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Canadian Politics Mega-thread Russo-Ukrainian War Thread The Big Programming Thread
Fan Clubs
The Happy Fan Club!
Media & Entertainment
Movie Discussion! [Manga] One Piece Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion MLB/Baseball 2023
World Cup 2022
Tech Support
Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread High temperatures on bridge(s)
TL Community
BarCraft in Tokyo Japan for ASL Season5 Final The Automated Ban List
Blogs
The Personality of a Spender…
TrAiDoS
A very expensive lesson on ma…
Garnet
hello world
radishsoup
Lemme tell you a thing o…
JoinTheRain
RTS Design in Hypercoven
a11
Evil Gacha Games and the…
ffswowsucks
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1173 users

The Big Programming Thread - Page 76

Forum Index > General Forum
Post a Reply
Prev 1 74 75 76 77 78 1031 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
Finland4567 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 1031 Next
Please log in or register to reply.
Live Events Refresh
PiGosaur Monday
00:00
#49
Liquipedia
OSC
23:00
OSC Elite Rising Star #16
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
WinterStarcraft529
StarCraft: Brood War
Leta 554
Noble 58
ajuk12(nOOB) 42
Icarus 9
Dota 2
NeuroSwarm134
Counter-Strike
Coldzera 532
Stewie2K437
semphis_42
Super Smash Bros
Mew2King35
Other Games
summit1g4944
C9.Mang0310
XaKoH 155
ViBE143
SortOf46
Trikslyr34
Organizations
Other Games
gamesdonequick667
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• OhrlRock 94
• intothetv
• AfreecaTV YouTube
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Lourlo1129
• Rush980
• Stunt374
Other Games
• Scarra1262
Upcoming Events
LiuLi Cup
6h 6m
OSC
14h 6m
RSL Revival
1d 5h
Maru vs Reynor
Cure vs TriGGeR
The PondCast
1d 8h
RSL Revival
2 days
Zoun vs Classic
Korean StarCraft League
2 days
BSL Open LAN 2025 - War…
3 days
RSL Revival
3 days
BSL Open LAN 2025 - War…
4 days
RSL Revival
4 days
[ Show More ]
Online Event
4 days
Wardi Open
5 days
Sparkling Tuna Cup
6 days
Liquipedia Results

Completed

Proleague 2025-09-10
Chzzk MurlocKing SC1 vs SC2 Cup #2
HCC Europe

Ongoing

BSL 20 Team Wars
KCM Race Survival 2025 Season 3
BSL 21 Points
ASL Season 20
CSL 2025 AUTUMN (S18)
LASL Season 20
RSL Revival: Season 2
Maestros of the Game
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1

Upcoming

2025 Chongqing Offline CUP
BSL World Championship of Poland 2025
IPSL Winter 2025-26
BSL Season 21
SC4ALL: Brood War
BSL 21 Team A
Stellar Fest
SC4ALL: StarCraft II
EC S1
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
MESA Nomadic Masters Fall
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
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 © 2025 TLnet. All Rights Reserved.