[Haskell-cafe] Syntax extension - adding import support to let/where bindings

amindfv at gmail.com amindfv at gmail.com
Wed Aug 5 14:38:44 UTC 2015


A couple syntactic concerns (assuming there's a sane semantics with eg typeclass instances):

 - This seems essentially like name shadowing, which is a source of confusion and therefore bugs (-Wall warns about it)
 - This makes me unable to see what a module imports by looking at the import statements at the top of a file
 - It seems like using "H.width" and "C.width" isn't very costly

Tom

El Aug 5, 2015, a las 6:28, Oliver Charles <ollie at ocharles.org.uk> escribió:

> Hi all,
> 
> I'm sure this has come up before, but a quick bit of Googling didn't reveal any prior discussions (if you known any, let me know), so I'm kicking off a new discussion.
> 
> I find myself wanting to be able to say something like:
> 
> foo = ...
>   where import Something.Specific
> 
> The result would be to import the contents of Something.Specific into the scope of foo and its other where bindings, but not import into the rest of the module that foo is defined in. As a motivating example, I'm currently working on building some HTML in Haskell, and the amount of symbols that come into scope is huge, when you have a DSL for both CSS and HTML - the real pain point being that you get symbols that often conflict.
> 
> Here's an example of something that doesn't type-check currently
> 
> image =
>   img [ width 50, style [ width (px 50) ] ]
> 
> width here is both a symbol in the HTML DSL and the CSS DSL, but to get this to type check I need to write something like
> 
> image =
>   img [ HTML.width 50, style [ CSS.width (CSS.px 50) ] ]
> 
> That's not particularly bad here, the really pain is repeatedly having to do this for every single symbol I'm using. I'd prefer to be able to write
> 
> image = 
>   let css = let import CSS in [ width (px 50) ]
>   in let import HTML in img [ width 50, style css ]
> 
> This is a little bit of a contrived rewrite, but hopefully it shows you what I'd like to be able to do. Please don't fixate too much on this example, it's only intended to illustrate the idea. When defining a large amount of inline styles I think this pays off - I import once to bring all the symbols I need into scope, rather than having to qualify every symbol.
> 
> In reality, it will lead to me writing code like:
> 
> myDocument = html
>   where html =
>           div [ style containerStyle ] 
>               [ div [ style rowStyle ] "Hello"
>               , div [ style rowStyle ] "World!" ]
>           where import HTML
>         containerStyle =
>           [ backgroundColor ..., padding ..., margin ... ]
>           where import CSS
>         rowStyle = 
>           [ backgroundColor ..., padding ..., margin ... ]
>           where import CSS
> 
> At present the suggestion is a syntax error, so I'm hoping that part won't be too controversial. 
> 
> Thoughts?
> ocharles
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150805/ab22cc1e/attachment.html>


More information about the Haskell-Cafe mailing list