[Ur] How to specify Name to be a field of record?

Vladimir Shabanov vshabanoff at gmail.com
Mon Dec 7 06:30:39 EST 2009


Hello. I'm trying to make some localized texts in my application. And
I want this texts to be selected from record (so I can use same field
name for html input id and text).

I have code like this:

val english_locale =
    { EMail = "E-Mail"
    , Keep  = "Keep me signed in"
    , Password = "Password"
    }
val russian_locale =
    { EMail = "E-Mail"
    , Keep  = "Запомнить меня"
    , Password = "Пароль"
    }

datatype language = En | Ru

fun locale m =
    case m of
        En => english_locale
      | Ru => russian_locale

fun ltext m [s] = (locale m).s

And I have some widget functions like this:

fun textbox [use ::: {Type}] [nm :: Name] [use ~ [nm = string]] (label:string) :
    xml [Body, Form, Table] use [nm = string] = <xml>
  <tr>
    <td class={Css.right}><label for={label}>{[label]}:</label></td>
    <td class={Css.left}><textbox{nm} id={label}/></td>
  </tr>
</xml>

in which I want to remove [label] argument, and use [ltext
cookie.locale nm] instead, so {textbox [#EMail] !} will insert field
with localized name (and create EMail field in form record at once).

Unfortunately [ltext] function doesn't type check. Ur has record
disjointness constraint, but here I need the opposite (and I think
some utility to take record type from value, to not write locale
record type separately).

How the type of [ltext] should be written?

Thanks.



More information about the Ur mailing list