G
Gergő Érdi
gergo.erdi.hu · Personal blog · on HN since 2011
Gergő Érdi writes about Haskell, type systems, retro hardware, FPGAs, and compiling to unusual targets like the 6502.
What HN saysCommenters link his posts on free applicatives and Rust on the 6502, and his Clash book on building retro chips in Haskell.
22HN people shared it
11linked it in comments
17stories submitted
398story points
10 months agolast shared
2011people per year2026
Most-shared posts
- 1MetaFun: Compile Haskell-like code to C++ template metaprograms8 people · 11 points · first shared 2014 · discussion on HN
- 22012 12 01 static analysis with applicatives3 people · first shared 2013
- 3Rust on the MOS 6502: Beyond Fibonacci2 people · 165 points · first shared 2021 · 39 comments on HN
- 4Developing iPhone applications in Haskell2 people · 10 points · first shared 2011 · discussion on HN
- 5Compiling Brainfuck to the MMU Turing tarpit via a MOVDBZ machine2 people · 6 points · first shared 2013 · 1 comments on HN
- 6Initial version of my Commodore PET2 people · 2 points · first shared 2015 · discussion on HN
- 7Write Yourself a Haskell in Lisp1 people · 129 points · first shared 2013 · 13 comments on HN
- 8A Brainfuck CPU in FPGA1 people · 61 points · first shared 2013 · 16 comments on HN
- 9Cheap and Cheerful Microcode Compression1 people · 3 points · first shared 2022 · discussion on HN
- 10Rust on AVR: Beyond Blinking1 people · 3 points · first shared 2017 · discussion on HN
- 11Building an FPGA computer with Haskell using Lava1 people · 3 points · first shared 2014 · discussion on HN
- 12A small benchmark for functional languages targeting web browsers1 people · 3 points · first shared 2022 · 1 comments on HN
- 13How I learned about Java's lack of type erasure the hard way (2011)1 people · 1 points · first shared 2017 · discussion on HN
- 14ICFP 2017 Bingo1 people · 1 points · first shared 2017 · discussion on HN
- 152010 10 23 the case for compositional type checking1 people · first shared 2017
What HN people wrote when they linked it
mietek · 2017-05-21
Your sketch of a proof does not appear substantially different from the proof given in section 3.1 of the linked paper. Section 3.2 explains that this result does not apply to strongly normalising languages.
See also the slides titled “So what about, e.g. Fω instead of ℕ ⇒ ℕ?” in Gergo Erdi’s talk on the subject of the linked paper:
https://gergo.erdi.hu/talks/2015-11-fomega/FOmegaUnquote.pdf
Note that your sketch is one particular variation of a folklore argument, best recalled by Conor McBride in 2003:
https://mail.haskell.org/pipermail/haskell-cafe/2003-May/004343.html
Here’s what Conor McBride has to say on the subject in 2015:
https://www.reddit.com/r/haskell/comments/38wels/conor_mcbride_hasochi…
If you are interested in discussing this further, please feel free to contact me privately.
dons · 2013-06-25
See also free applicatives. We use these extensively at work. E.g. http://gergo.erdi.hu/blog/2012-12-01-static_analysis_with_applicatives…
Amazing when entire DSL programs turn into 1 line calls.
gergoerdi · 2017-08-21
One drawback of the Hindley-Milner type system is that its typecheckers are necessarily non-compositional. The basic idea here is that this can result in "non-symmetrical" error messages[1]: given something like
MkPair :: a -> b -> Pair a b
not :: Bool -> Bool
succ :: Int -> Int
foo x = MkPair (succ x) (not x)
the error message will either complain that `x` has type `Bool` but it should be `Int`, or it will complain that `x` has type `Int` but it should be `Bool` -- depending on what implementation you use! For example, in Haskell, Hugs 98 will emit the first error message, but GHC 7.10 will emit the second (see the full example in my slides[2]). And in some sense, neither is right (and certainly neither is as helpful for the programmer as it could be).
So next time you're implementing vanilla HM, maybe consider a compositional type system[3] instead, which can give the following, much more informative error message:
Cannot unify 'Int' with 'Bool' when unifying 'x':
Cannot unify 'Int' with 'Bool' in the following context:
MkPair (succ x) (not x)
Bool -> Pair Int Bool Bool
x :: Int Bool
I have a simple implementation here[4], and am about to release a new version which works on `haskell-src-ext`'s AST to support more of Haskell 98 syntax (but still for vanilla HM only).
[1] https://gergo.erdi.hu/blog/2010-10-23-the_case_for_compositional_type_…
[2]…
ladyanita22 · 2024-05-25
There's also this https://gergo.erdi.hu/blog/2021-09-18-rust_on_the_mos_6502__beyond_fib… for rust on the 6502.
I wonder how's the performance vs. C (for both, C# and Rust).
Edit: It's my understanding that the 6502 is extremely stack-limited, so a well-versed assembler would use the stack very little and allocate mostly on the heap. In C, you can replicate this with global variables, and I believe (and I would be very happy if someone related to the 6502 rust port could chime in here) on Rust you can do the same with `static mut` on Rust 2021 and `Unsafecell` on Rust 2024.
kryptiskt · 2022-05-25
Pong is one of the sample chapters for the "Retrocomputing with Clash" book (https://gergo.erdi.hu/retroclash/). Clash is a hardware description DSL using Haskell, and the book is all about using it to implement progressively more complex 1970s chips.
cfallin · 2016-02-05
Yup, it's definitely its own language! It made me so happy when I saw a Haskell-to-C++-template compiler [1] because of all the similarities in pure-FP style (pattern matching, iteration via recursion, etc).
[1] https://gergo.erdi.hu/projects/metafun/
emillon · 2015-07-01
This kind of compiler has already be done: http://gergo.erdi.hu/projects/metafun/
pbsd · 2015-02-08
I have seen more than one such compiler, usually from Haskell-like dialects to C++ metafunctions (e.g., http://gergo.erdi.hu/projects/metafun/).
In this case the metaprogramming seems unnecessary---even assuming that it makes any sense to run a snake game at compile time---since C++14's relaxed `constexpr` functions are a much more readable way to achieve the same thing. Metaprogramming is only required now when types need to be computed; most of everything else is more cleanly done with `constexpr`.
eru · 2014-10-27
> Maybe it's just me, but I've never found most functional code I've seen to be particularly declarative. I certainly like purity and immutability, but much of it still reads imperatively to me, just in a slightly more abstract style.
How much have you seen? If you can understand Haskell, the ideas in http://gergo.erdi.hu/blog/2012-12-01-static_analysis_with_applicatives… are pretty neat and directly exploit declarations.
zem · 2014-03-20
you should find metafun interesting: http://gergo.erdi.hu/projects/metafun/
gtani · 2012-04-09
read this, in Hungarian
http://gergo.erdi.hu/blog/2011-05-16-i%27m_leaving_on_a_jet_plane.../
google translate:
rapid help deszantosokként trapped in the trade analysts,