We could have something like<div><br></div><div>class DomId a where</div><div>  toDomId :: a -&gt; Text</div><div><br></div><div><div>class DomClass a where</div><div>  toDomClass :: a -&gt; Text</div></div><div><br></div>

<div>That hamlet calls on id and class insertions. Michael would no better if that is possible with the hamlet internals.</div><div><br></div><div><br><div class="gmail_quote">On Fri, Apr 8, 2011 at 7:03 AM, Max Cantor <span dir="ltr">&lt;<a href="mailto:mxcantor@gmail.com">mxcantor@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">In an effort to get more type-checked goodness in hamlet, I started using string constants for all my dom IDs and classes.  We&#39;re not using the newIdent function because I want control over what the IDs and classes will be named.<br>


<br>
I wrote up a little typeclass as such:<br>
<br>
class CustomIdentString a where jqVal :: a -&gt; String; idVal :: a -&gt; String<br>
<br>
newtype CustomIdentCls = MkCls String<br>
instance CustomIdentString CustomIdentCls where<br>
  jqVal (MkCls s) = &quot;.&quot; ++ s; idVal (MkCls s) = s;<br>
<br>
newtype CustomIdentId = MkId String<br>
instance CustomIdentString CustomIdentId where<br>
  jqVal (MkId s) = &quot;#&quot; ++ s; idVal (MkId s) = s;<br>
<br>
This way, I can refer to divs in javascript using:<br>
$(&quot;#{jqVal myId}&quot;).foo..<br>
<br>
And create the elements in hamlet using<br>
&lt;div ##{idVal myId}&gt; ...<br>
<br>
I&#39;m wondering is there a datatype for IDs and Classes that I can use to make the IDs and Classes directly so that:<br>
&lt;div .#{foo myId}&gt; and &lt;div ##{foo myCls}&gt;<br>
would fail to typecheck?<br>
<br>
In general, are there any good, safe ways to do this instead of just unwrapping to strings?<br>
<br>
max<br>
_______________________________________________<br>
web-devel mailing list<br>
<a href="mailto:web-devel@haskell.org">web-devel@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/web-devel" target="_blank">http://www.haskell.org/mailman/listinfo/web-devel</a><br>
</blockquote></div><br></div>