representation

Methods for Python classes representation

女生的网名这么多〃 提交于 2019-12-04 07:20:19
I know that methods __repr__ and __str__ exist to give a formal and informal representation of class instances. But does an equivalent exist for class objects too, so that when the class object is printed, a nice representation of it could be shown? >>> class Foo: ... def __str__(self): ... return "instance of class Foo" ... >>> foo = Foo() >>> print foo instance of class Foo >>> print Foo __main__.Foo unutbu When you call print(foo) , foo 's __str__ method is called. __str__ is found in the class of foo , which is Foo . Similarly, when you call print(Foo) , Foo 's __str__ method is called. _

2's complement representation of fractions?

China☆狼群 提交于 2019-12-04 04:28:11
问题 I'm a little lost on this. I need to use two fractional bits 0.(a-1)(a-2) Like that, now I can use .00 .01 .10 and .11 But I need negative numbers (in 2's complement) also, so would .10 be -.5 ? or would it be -.25 ? The same with .11 , that would be -.75 ? or would it be -.5 ? I'm pretty sure it would be the former in both cases, but I'm not entirely positive. 回答1: In two's complement notation, all of the most significant bits of a negative number are set to 1. Let's assume you're storing

Changing internal representation in runtime

烈酒焚心 提交于 2019-12-03 21:26:42
UPDATE The main questions remain the ones under the example, but I guess it boils down to : **If you have a type where 99% of the values could be represented in one fast, powerfull type, and only 1% in a very heavy type, (say int vs. BigInteger) How to represent it?? ** A school we learned a lot about internal representations, but never how to change it at runtime. I mean : suppose you have a class representing a decimal, but you use an integer to represent it internal, until you actually need a bigger value than the integer, and only than change representation... I never thought of this

Why is the undefined function levity-polymorphic when using it with unboxed types?

ⅰ亾dé卋堺 提交于 2019-12-03 11:47:19
问题 I just got finished reading the paper Levity Polymorphism. I had a question about why undefined can be levity-polymorphic when used as an unboxed type. First, let's start with some definitions of boxity from the paper: boxed : A boxed value is represented by a pointer into the heap. Int and Bool are examples of types that have boxed values. unboxed : An unboxed value is represented by the value itself ( not a pointer to the heap). Int# and Char# from the GHC.Prim module are examples of types

Finite automaton in Haskell

蹲街弑〆低调 提交于 2019-12-03 05:46:34
问题 What is a good way to represent finite automaton in Haskell? How would the data type of it look like? In our college, automata were defined as a 5-tuple (Q, X, delta, q_0, F) where Q is the set of automaton's states, X is the alphabet (is this part even necessery), delta is the transition function taking 2-tuple from (Q,X) and returning state/-s (in non-deterministic version) and F is the set of accepting/end states. Most importantly, I'm not sure what type delta should have... 回答1: There are

Haskell - How to best to represent a programming language's grammar?

僤鯓⒐⒋嵵緔 提交于 2019-12-03 01:32:31
问题 I've been looking at Haskell and I'd quite like to write a compiler in it (as a learning exercise), since a lot of its innate features can be readily applied to a compiler (particularly a recursive descent compiler). What I can't quite get my head around is how to represent a language's grammar in a Haskell-ian way. My first thought was to use recursive data type definitions, but I can't see how I use them to match against keywords in the language ("if") for example. Thoughts and suggestions

Is there any graphical representation of Android views lifecycle (a state diagram)? [closed]

喜欢而已 提交于 2019-12-03 01:09:56
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . We all know about the Android Activity's life cycle and Fragment's life cycles. But is there anything equivalent for views ? This could help, for instance, building custom views or give an in-depth look at a very common and often hidden graphic operation on Android. Thanks in advance ! 回答1: It isn't an official

Finite automaton in Haskell

北城以北 提交于 2019-12-02 19:17:26
What is a good way to represent finite automaton in Haskell? How would the data type of it look like? In our college, automata were defined as a 5-tuple (Q, X, delta, q_0, F) where Q is the set of automaton's states, X is the alphabet (is this part even necessery), delta is the transition function taking 2-tuple from (Q,X) and returning state/-s (in non-deterministic version) and F is the set of accepting/end states. Most importantly, I'm not sure what type delta should have... There are two basic options: An explicit function delta :: Q -> X -> Q (or [Q] as appropriate) as Sven Hager suggests

Biggest number in computer ever

拈花ヽ惹草 提交于 2019-12-02 15:32:34
Just asked by my 5 year old kid: what is the biggest number in the computer? We are not talking about max number for a specific data types, but the biggest number that a computer can represent. Infinity is not allowed. UPDATE my kid always wants to print as well, so lets say the computer needs to print this number and the kid to know that its a big number. Of course, in practice we won't print because theres not enough trees. This question is actually a very interesting one which mathematicians have devoted a fair bit of thought to. You can read about it in this article , which is a

Haskell - How to best to represent a programming language's grammar?

给你一囗甜甜゛ 提交于 2019-12-02 14:56:23
I've been looking at Haskell and I'd quite like to write a compiler (as a learning exercise) in it, since a lot of it's innate features can be readily applied to a compiler (particularly a recursive decent compiler). What I can't quite get my head around is how to represent a language's grammar in a Haskell-ian way. My first thought was to use recursive data type definitions, but I can't see how I use them to match against keywords in the language ("if") for example. Thoughts and suggestions greatly appreciated, Pete A recursive data type is fine for this. For example, given the language: expr