instance

Haskell show instance on list

霸气de小男生 提交于 2019-12-02 06:47:59
Im having issues with adding a show instance to my data structure, wich is: data Structure = Structure String [Structure] and I would like to have this output: strct strct1 strct2 strct3 I've been trying this instance Show Structure where show (Structure a (xs)) = show a ++ "\n" ++ " " ++ show xs But its output is "strct" ["strct1" [], "strct2" []] So, I would need no brackets, no commas and no quotation marks. Any ideas? Thanks I'm sure there are better library routines for this, but wouldn't this work? unlines $ a : [" " ++ show x | x <- xs] However, that covers only one level. You probably

defining repr() of classes (not instances)

江枫思渺然 提交于 2019-12-02 05:04:38
问题 I have a bunch of classes which I'm using as singletons / enums / dict keys, e. g. like this: class Side(object): pass class Left(Side): pass class Right(Side): pass def show_state(distribution): print "left is", distribution[Left] print "right is", distribution[Right] distribution = { Left: 3, Right: 7 } show_state(distribution) This works fine for me. But I'm having a small issue with debug output I sometimes do. Normally I use just print for this like in print distribution in the show

Get current VaadinContext and current VaadinSession (both places to store state as “attribute” key-value pairs) in Vaadin Flow

ⅰ亾dé卋堺 提交于 2019-12-02 05:01:38
问题 In using Vaadin Flow, version 14, I know we can store state as key-value pairs kept as "attributes" via getAttribute / setAttribute / removeAttribute methods found on: VaadinSession (per-user scope) VaadinContext (web-app scope) How does one access the current object for those classes? 回答1: VaadinSession.getCurrent() For that per-user scope , the VaadinSesion class provides a static class method getCurrent to access the current instance. VaadinSession session = VaadinSession.getCurrent() ; //

Declare all instances of a typeclass are in another typeclass without modifying the original class declarations

喜欢而已 提交于 2019-12-02 04:46:07
There is an Crypto.Random API inside the crypto-api package that specifies what it means for something to be a "pseudorandom number generator". I have implemented this API using an instance of System.Random's RandomGen class, namely, StdGen: instance CryptoRandomGen StdGen where newGen bs = Right $ mkStdGen $ shift e1 24 + shift e2 16 + shift e3 8 + e4 where (e1 : e2 : e3 : e4 : _) = Prelude.map fromIntegral $ unpack bs genSeedLength = Tagged 4 genBytes n g = Right $ genBytesHelper n empty g where genBytesHelper 0 partial gen = (partial, gen) genBytesHelper n partial gen = genBytesHelper (n-1)

Put objects into bundle

限于喜欢 提交于 2019-12-02 04:38:44
Greetings, I have a game, and i want to save the objects ( creatues ) that move on canvas to a bundle so that when someone pauses/leaves the app, the objects can stay where they were. I have looked at the LunarLanding game where they save the coordinates of the space shuttle into bundles and read from them and i want to do same ( if there is no better way ) but i have objects of a custom type and i am not sure how to save them and read from the bundle. I could do the save of all the parts of the object individually and put them back together, but i have a lot of objects and that would just be

Can you declare an instance variable as a parameter in a constructor?

微笑、不失礼 提交于 2019-12-02 04:02:35
Would this work? class Cars{ Cars(int speed, int weight) } I am just trying to figure out the constructor. If it is called like a method then I thought it would work similar to a method. You can create local variables in a method that are used when that method is called so I don't see why instance variables have to be declared before constructors can use them. In your example speed and weight are not instance variables because their scope is limited to the constructor. You declare them outside in order to make them visible throughout the whole class (i.e. throughout objects of this class). The

Java: how to access outer class's instance variable by using “this”?

爱⌒轻易说出口 提交于 2019-12-02 03:57:46
问题 I have a static inner class, in which I want to use the outer class's instance variable. Currently, I have to use it in this format "Outerclass.this.instanceVariable", this looks so odd, is there any easier way to access the instance field of the outer class? Public class Outer { private int x; private int y; private static class Inner implements Comparator<Point> { int xCoordinate = Outer.this.x; // any easier way to access outer x ? } } 回答1: A static nested class cannot reference the outer

here different instances are generated for this template function or not?

ε祈祈猫儿з 提交于 2019-12-02 03:55:20
Considering following struct and template function, does each use of the function with a different value for "num" build a new instance of the function or since const numbers<num> & nums parameter is a reference and would be implemented as a pointer all uses with different values for "num" can be directed to one instance of the function? template<size_t num> struct numbers{ public: unsigned int nums[num]; }; template<size_t num> void print(const numbers<num> & nums,size_t size){ for (int i=0;i<size;i++) cout <<nums.nums[i]<<' '; cout <<'\n'; } As far as you (the programmer) are concerned,

How to count the number of instance of a custom class?

不问归期 提交于 2019-12-02 03:39:35
问题 I would like to count the number of instances of a custom class and its subclasses in Python3.x. How to do? Thank you very much. I have tried the way class-member, but it doesn't work. The following are the codes Base.py class Base: ## class members __counter = int(0) @classmethod def _count(cls): cls.__counter += 1 return cls.__counter def __init__(self): self.__id = self._count() @property def id(self): return self.__id SubBase1.py from Base import Base class SubBase1(Base): def __init__

I cannot access Position of the cursor (move mouse programatically)

≡放荡痞女 提交于 2019-12-02 03:09:07
this is my code: private void MoveCursor(int x, int y) { // Set the Current cursor, move the cursor's Position, // and set its clipping rectangle to the form. System.Windows.Forms.Cursor cursorMouse = new System.Windows.Forms.Cursor(System.Windows.Forms.Cursor.Current.Handle); cursorMouse.Position = new System.Drawing.Point(x, y); System.Windows.Forms.Cursor.Clip = new System.Drawing.Rectangle(cursorMouse.Position, cursorMouse.Size); } This is what my console says: Error 11 Member 'System.Windows.Forms.Cursor.Position.get' cannot be accessed with an instance reference; qualify it with a type