... had this been written in a language less esoteric than Haskell, it would've been even better for the rest of us :)
I think it's too bad we don't have module interoperability. There's never going to be just one programming language. The situation on the JVM -- where Scala, Java and Kotlin can use one another's modules -- is a positive example. Clang modules and Swift's auto-magic import of them is another.
Show HN: Legion, an as-simple-as-possible blockchain server written in Haskell
21–30 of 73 posts
Re: Show HN: Legion, an as-simple-as-possible blockchain server written in Haskell
#22Earlier quoted context omitted.
A very simple proof of work is adding a token to the data before hashing: sha256(token + data + previous hash) i.e. (for simplicity, previous hash = "") sha256("1" + "example" + PreviousHash) -> ee73735c2355bc4d63319a6638e356ef42d0d56746317c99f52d3e7ac71cbf52 sha256("2" + "example" + PreviousHash) -> 6236cd42286c74a1683eaf394b3b2f40a3a52479e1a3d7e732175fcdfa49b931 ... sha256("10" + "example" + PreviousHash) -> 346fea…
Note that "the first X characters" is kind of misleading, because it is usually more fine grained. It is better (and IMHO even simpler!) to think of the hash as a large integer, not a string. Then you want that integer to be smaller than a certain value. With strings, you can only say: "00123" shall start with "00", while wih integers, you would say: 00123 shall be smaller than 300. (To be that fine grained with stri…
Re: Show HN: Legion, an as-simple-as-possible blockchain server written in Haskell
#23Earlier quoted context omitted.
Correct, the goal for this was as minimal as possible. However, if I (or anyone wanting to contribute) can come up with a very compact way to implement that, we could definitely add it!
A very simple proof of work is adding a token to the data before hashing: sha256(token + data + previous hash) i.e. (for simplicity, previous hash = "") sha256("1" + "example" + PreviousHash) -> ee73735c2355bc4d63319a6638e356ef42d0d56746317c99f52d3e7ac71cbf52 sha256("2" + "example" + PreviousHash) -> 6236cd42286c74a1683eaf394b3b2f40a3a52479e1a3d7e732175fcdfa49b931 ... sha256("10" + "example" + PreviousHash) -> 346fea…
Re: Show HN: Legion, an as-simple-as-possible blockchain server written in Haskell
#24Earlier quoted context omitted.
Note that "the first X characters" is kind of misleading, because it is usually more fine grained. It is better (and IMHO even simpler!) to think of the hash as a large integer, not a string. Then you want that integer to be smaller than a certain value. With strings, you can only say: "00123" shall start with "00", while wih integers, you would say: 00123 shall be smaller than 300. (To be that fine grained with stri…
I agree with the gist, but note that even with strings, "00122" is less than "00200" :)
Re: Show HN: Legion, an as-simple-as-possible blockchain server written in Haskell
#25Earlier quoted context omitted.
I think it's too bad we don't have module interoperability. There's never going to be just one programming language. The situation on the JVM -- where Scala, Java and Kotlin can use one another's modules -- is a positive example. Clang modules and Swift's auto-magic import of them is another.
I'm pretty uninformed about libffi but can it help with kind of module interoperability? I've used it to get Ruby to call C functions. I would guess that it could be used for other dynamic languages to call compiled functions such as JS to Haskell like the OP seems to be desiring. Is this true?
Re: Show HN: Legion, an as-simple-as-possible blockchain server written in Haskell
#26Earlier quoted context omitted.
I think it's too bad we don't have module interoperability. There's never going to be just one programming language. The situation on the JVM -- where Scala, Java and Kotlin can use one another's modules -- is a positive example. Clang modules and Swift's auto-magic import of them is another.
I'm pretty uninformed about libffi but can it help with kind of module interoperability? I've used it to get Ruby to call C functions. I would guess that it could be used for other dynamic languages to call compiled functions such as JS to Haskell like the OP seems to be desiring. Is this true?
Re: Show HN: Legion, an as-simple-as-possible blockchain server written in Haskell
#27Re: Show HN: Legion, an as-simple-as-possible blockchain server written in Haskell
#28Earlier quoted context omitted.
A very simple proof of work is adding a token to the data before hashing: sha256(token + data + previous hash) i.e. (for simplicity, previous hash = "") sha256("1" + "example" + PreviousHash) -> ee73735c2355bc4d63319a6638e356ef42d0d56746317c99f52d3e7ac71cbf52 sha256("2" + "example" + PreviousHash) -> 6236cd42286c74a1683eaf394b3b2f40a3a52479e1a3d7e732175fcdfa49b931 ... sha256("10" + "example" + PreviousHash) -> 346fea…
Note that "the first X characters" is kind of misleading, because it is usually more fine grained. It is better (and IMHO even simpler!) to think of the hash as a large integer, not a string. Then you want that integer to be smaller than a certain value. With strings, you can only say: "00123" shall start with "00", while wih integers, you would say: 00123 shall be smaller than 300. (To be that fine grained with stri…
0 == hash >> (hash_length - prefix_length)
Or, alternatively: !(hash & prefix_mask)
where `prefix_mask` is 1111..000, with `prefix_length` number of 1s.I think that working in terms of bitstrings generated by the hash gives more context to why those integers are chosen (that they represent a certain portion of the space of possible answers), but it's also a matter of taste/background.
Re: Show HN: Legion, an as-simple-as-possible blockchain server written in Haskell
#29One question:
getBlockChain :: (SpockState m ~ BlockChainState, MonadIO m, HasSpock m) => m [Block]
What does the squiggle mean?Re: Show HN: Legion, an as-simple-as-possible blockchain server written in Haskell
#30Nicely done. It reads like Ikea instructions. I didn't really know how blockchain worked until I read this code. If this was written as a teaching tool or a portfolio piece or even an art project, then I say its a big success. One question: getBlockChain :: (SpockState m ~ BlockChainState, MonadIO m, HasSpock m) => m [Block] What does the squiggle mean?