[Ur] More questions

Adam Chlipala adamc at impredicative.com
Sun Dec 12 18:16:13 EST 2010


Marc Weber wrote:
> 1)
>    Is using mapM the best choice?
>    Haskell has sequence or sequence_
>    Anyway: No inserts take place. What am I doing wrong?
>
>      fun speed_test_insert () =
>        let
>          val numbers = Enum.to 1 10
>        in
>          dml (DELETE FROM st WHERE 1 = 1);
>          list<- (List.mapM (fn i =>  dml (INSERT INTO st (Id, A, B, C) VALUES ({[i]}, {["TEXT A"]}, {["TEXT B"]}, {["TEXT C"]}) ) ) numbers);
>          return (page "refreshed"<xml>{[show numbers]}</xml>)
>        end
>    

I think [List.app] is the better choice.

I don't see any obvious problem in the above that would lead to no rows 
being inserted, but I don't know which code for [Enum.to] you have in 
mind.  I'd guess there's a bug where it's returning an empty list.

BTW, you could write [TRUE] instead of [1 = 1].  IMO, it's slightly 
nicer looking.

> 2)
>    Tree demo:
>        A witness that key belongs to the type class sql_injectable_prim,
>        which indicates that both key and option key are fair game to use with SQL
>
>    What does this exactly mean?
>    

[sql_injectable] is an abstract type family.  This means that its 
definition is not exposed by its containing module, [Basis].  Thus, 
values in this type family can only be built using combinators exposed 
by [Basis].  There is a value for building [sql_injectable int], but it 
is impossible to construct a value of type [sql_injectable (int -> int)].

That behavior is appropriate because [sql_injectable] is meant as a type 
of proofs that particular types are understood by the SQL engine.  
Haskell type classes are always open, where any module may add new 
instances.  The [sql_injectable] class in Ur/Web is closed, which makes 
it suitable as a type of proofs with a fixed meaning.  While the 
dictionary-passing implementation of type classes is only implicit in 
Haskell, it is explicit in Ur, so that [sql_injectable] values may 
either be passed manually or found automatically by type class resolution.



More information about the Ur mailing list