4 ms·
All of my sibling posts: please be specific!! Somebody not at your level (and there's more for Haskell than more mainstream languages)... like me... isn't going
by fn-mote 4y ago
All of my sibling posts: please be specific!! Somebody not at your level (and there's more for Haskell than more mainstream languages)... like me... isn't going to get what you're talking about.
> And if you won't learn the hard idioms at all ... you will never get most of the value.
Ok... mention a hard idiom? Even if you don't want to go into detail. We'll look it up.
> [...] reading someone else's Haskell code insanely difficult.
I'm wondering if that's because they used a ton of operators like (.)(.)(.) or :=-=: (just made that up, i hope), or was it because of some deeper reason like too much magic hidden in the monad transformers. Anything concrete you're willing to say will clear some of this haze of non-understanding.
- spion 4y agoOk, lets be specific. Lets write a comment to explain this function: https://github.com/dhall-lang/dhall-haskell/blob/master/dhall-json/src/Dhall/JSONToDhall.hs#L802-L809 https://github.com/dhall-lang/dhall-haskell/blob/master/dhal...
- rowanG077 4y agoThere is already a comment there? And the implementation doesn't look too hard. I don't feel like this is an example of a hard to understand Haskell function.
- spion 4y agoHow about you try your best to explain all of it? What exactly is that you understand here? What does Optics.rewriteOf do? What's the purpose of Lint.useToMap? How about D.subExpressions ? How does that composition work with the loop function? Even better. How would you go about finding the source code containing the definition of the function `D.subExpressions` ?
- rowanG077 4y agoNo I didn't understand every sub-function in this function. That isn't necessary to get an idea of what a function does. All of your questions can be answered incredible quickly though using https://hoogle.haskell.org/ https://hoogle.haskell.org/ > What does Optics.rewriteOf do? Hoogling show this is an alias of https://hackage.haskell.org/package/lens-5.1.1/docs/Control-Lens-Combinators.html#v:rewriteOf https://hackage.haskell.org/package/lens-5.1.1/docs/Control-.... > What's the purpose of Lint.useToMap? Hoogle again shows https://hackage.haskell.org/package/dhall-1.41.1/docs/Dhall-Lint.html#v:useToMap https://hackage.haskell.org/package/dhall-1.41.1/docs/Dhall-.... If your function is not indexed you can look at what is qualified as `Lint` and look it up that way. > How about D.subExpressions ? How does that composition work with the loop function? https://hackage.haskell.org/package/dhall-1.41.1/docs/Dhall-Core.html#v:subExpressions https://hackage.haskell.org/package/dhall-1.41.1/docs/Dhall-... All nicely documented... I'm not sure what you mean by composition with the loop function. First the loop function is executed and then afterwards over the result the expression in the first argument to fmap is applied. There is no weird interaction going on here. It's just run this over the result of the loop function if it didn't produce an error. > Even better. How would you go about finding the source code containing the definition of the function `D.subExpressions` ? Use hoogle or just look at the imports at the top of the file. Just like any other programming language. Or even better, use the language server to find it for you. For example there is an import here: `import qualified Dhall.Core as D` Now you know that function is in the `Dhal.Core` module. Going to that module you see the function is not actually there but is exported from the `Dhal.Syntax` module. It took me literally 5 seconds to find it: https://github.com/dhall-lang/dhall-haskell/blob/master/dhall/src/Dhall/Syntax.hs#L786 https://github.com/dhall-lang/dhall-haskell/blob/master/dhal...
- spion 4y ago> Hoogling show this is an alias of https://hackage.haskell.org/package/lens-5.1.1/docs/Control- https://hackage.haskell.org/package/lens-5.1.1/docs/Control-... That explains nothing? What does it do? How does it do it? What do the type variables `a b a b` mean? Why are there 4 of them? What is ASetter?
- 4y ago
- spion 4y agoThe density of that code is just insanely high. In most language that single fmap line would likely be at least 5 lines of code with lots of variable names to aid in understanding. The map rewrite traversal and actual "compiler" loop part would be separated for sure, and `(D.alphaNormalize (D.normalize expressionType))` would be assigned to another intermediate variable as a "preprocessing step"
- spion 4y agoHere is the documentation I would write for a function like this, in a normal language: {-| Given `Conversion` options and a Dhall type `ExprX`, try to convert the JSON value `Value` to a Dhall expression of the specified type. Additionally, if the conversion is successful, apply a rewrite on all maps in the key-value map pair format to map nodes (i.e. `[{ mapKey = "foo", mapValue = 1 }] -> toMap {foo = 1}`) -} And here is how I would decompose the first part dhallFromJSON (Conversion {..}) expressionType value = do let normalizedType = D.alphaNormalize (D.normalize expressionType) dhallExpression <- loop [] normalizedType value -- Rewrite maps return $ Optics.rewriteOf D.subExpressions Lint.useToMap dhallExpression
- lolinder 4y agoApologies in advance for the meta comment, but: could you just reply to the comments you're replying to, instead of their parent? Trying to find the context for your quote extracts is more difficult than it needs to be.