language-implementation

How does a Haskell compiler work?

别等时光非礼了梦想. 提交于 2019-12-02 14:10:59
Where can I get some paper/doc/whatever which describes how a Haskell compiler actually works? I read quite a few of the docs of GHC, but stopped after getting a headache. So, something which doesn't require a PhD to understand it and isn't written in the You're-supposed-to-be-already-familiar-with-it style would be preferable. It's not a problem if it's really long and takes some time to understand it though. PS: Most interesting would be something about GHC, but anything is ok. You can get an answer from the horse's mouth! Simon Peyton Jones (GHC wizard) wrote a book explaining how to

Access iterator object within a debugger

爷,独闯天下 提交于 2019-12-02 13:20:27
Is there really no way to access the iterator object or its state from inside a for-loop? Using pdb or ipdb for example, I can loop over and over again with n , but not see in which iteration I am (ex post, I mean; of course I could use enumerate, but only before starting the debugger). def creates an object, and for does the same, doesn't it? But the function has a name - and the iterator has not, is not accessible in memory? By the way, is the function accessible from within its body without knowing the name? (The answers to questions Python: access to iterator-object in for-loops and

Where is it specified whether Unicode identifiers should be allowed in a Haskell implementation?

扶醉桌前 提交于 2019-12-01 03:28:07
I wanted to write some educational code in Haskell with Unicode characters (non-Latin) in the identifiers. (So that the identifiers look nice and natural for speakers of a natural language other than English which is not using the Latin characters in its writing.) So, I set out for finding an appropriate Haskell implementation that would allow this. But where is this feature specified in the language specification? How would I refer to this feature when looking for a conforming implementation? (And which Haskell implemenations are known to actually support Unicode identifiers?) It turned out

How to implement a practical fiber scheduler?

别来无恙 提交于 2019-11-30 14:08:20
问题 I know the very basics about using coroutines as a base and implementing a toy scheduler. But I assume it's oversimplified view about asynchronous schedulers in whole. There are whole set of holes missing in my thoughts. How to keep the cpu from running a scheduler that's running idle/waiting? Some fibers just sleep, others wait for input from operating system. 回答1: You'd need to multiplex io operations into an event based interface(select/poll), so you can leverage the OS to do the waiting,

Why does binding affect the type of my map?

耗尽温柔 提交于 2019-11-30 11:18:52
I was playing around in the REPL and I got some weird behavior: Clojure 1.4.0 user=> (type {:a 1}) clojure.lang.PersistentArrayMap user=> (def x {:a 1}) #'user/x user=> (type x) clojure.lang.PersistentHashMap I thought that all small literal maps were instances of PersistentArrayMap , but apparently that's not the case if it's been bound with def . Why would using def cause Clojure to choose a different representation for my litte map? I know it's probably just some strange implementation detail, but I'm curious. This question made me dig into the Clojure source code. I just spent a few hours

How to implement a practical fiber scheduler?

孤者浪人 提交于 2019-11-30 09:06:48
I know the very basics about using coroutines as a base and implementing a toy scheduler. But I assume it's oversimplified view about asynchronous schedulers in whole. There are whole set of holes missing in my thoughts. How to keep the cpu from running a scheduler that's running idle/waiting? Some fibers just sleep, others wait for input from operating system. You'd need to multiplex io operations into an event based interface(select/poll), so you can leverage the OS to do the waiting, while still being able to schedule other fibers. select/poll have a timeout argument - for fibers that want

Why must Python list addition be homogenous?

守給你的承諾、 提交于 2019-11-30 08:05:10
Can anyone familiar with Python's internals (CPython, or other implementations) explain why list addition is required to be homogenous: In [1]: x = [1] In [2]: x+"foo" --------------------------------------------------------------------------- TypeError Traceback (most recent call last) C:\Users\Marcin\<ipython-input-2-94cd84126ddc> in <module>() ----> 1 x+"foo" TypeError: can only concatenate list (not "str") to list In [3]: x+="foo" In [4]: x Out[4]: [1, 'f', 'o', 'o'] Why shouldn't the x+"foo" above return the same value as the final value of x in the above transcript? This question follows

How is C++'s multiple inheritance implemented?

故事扮演 提交于 2019-11-30 04:44:13
Single inheritance is easy to implement. For example, in C, the inheritance can be simulated as: struct Base { int a; } struct Descendant { Base parent; int b; } But with multiple inheritance, the compiler has to arrange multiple parents inside newly constructed class. How is it done? The problem I see arising is: should the parents be arranged in AB or BA, or maybe even other way? And then, if I do a cast: SecondBase * base = (SecondBase *) &object_with_base1_and_base2_parents; The compiler must consider whether to alter or not the original pointer. Similar tricky things are required with

Why does Python have a limit on the number of static blocks that can be nested?

半腔热情 提交于 2019-11-29 22:46:57
The number of statically nested blocks in Python is limited to 20. That is, nesting 19 for loops will be fine (although excessively time consuming; O(n^19) is insane), but nesting 20 will fail with: SyntaxError: too many statically nested blocks What is the underlying reason for having such a limit? Is there a way to increase the limit? This limit not only applies to for loops, but to all other control flow blocks as well. The limit for the number of nested control flow blocks is defined inside of code.h with a constant named CO_MAXBLOCKS : #define CO_MAXBLOCKS 20 /* Max static block nesting

Why does binding affect the type of my map?

浪子不回头ぞ 提交于 2019-11-29 16:57:46
问题 I was playing around in the REPL and I got some weird behavior: Clojure 1.4.0 user=> (type {:a 1}) clojure.lang.PersistentArrayMap user=> (def x {:a 1}) #'user/x user=> (type x) clojure.lang.PersistentHashMap I thought that all small literal maps were instances of PersistentArrayMap , but apparently that's not the case if it's been bound with def . Why would using def cause Clojure to choose a different representation for my litte map? I know it's probably just some strange implementation