--
You received this message because you are subscribed to the Google Groups "ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/EC973B28-C1E1-441A-8771-7B60639DD046%40shealevy.com.
On Apr 14, 2015, at 9:33 PM, Hongwei Xi <gmh...@gmail.com> wrote:There are two issues here.1. Syntax. The following declaration is what you want:
dataview partial_buf ( t: t@ype, int, int, addr ) =
| { fill, total: nat | fill <= total }{ buf : addr }
partial_buf ( t
, fill
, total
, buf
) of ( @[ t ][ fill ] @ buf
, @[ t? ][ total - fill ] @ ( buf + fill )
)If a parameter is given a name in a dataview declaration, then a universalquantifier is implicitly introduced for that parameter. So your original declarationhas duplicated quantifiers.
2. Logic.
implement main () = let
var buf = @[byte][10]()
prval empty = array_v_nil{byte}()
prval partial = partial_buf(empty, view@(buf))
prval partial_buf(empty, l) = partial
prval _ = array_v_unnil(empty)
prval _ = view@(buf) := l
in 0 end
>>prval partial_buf(empty, l) = partialThe system does not know that 'empty' is a proof of an empty array-view;it only knows that 'empty' is a prefix of the given buffer.
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/CAPPSPLp4bFMpFZ9AiJ0ff%3D%2BAap6fDigSrkvNCU_73_24_HAc8w%40mail.gmail.com.
implement main () = let
var buf = @[byte][10]()
prval pfbuf = view@(buf)
prval pfemp = array_v_nil{byte}{buf}()
prval partial = partial_buf{byte}{0,10}{..}(pfemp, pfbuf)
prval partial_buf{..}{fill,total}{buf2}(empty, l) = partial
prval _ = array_v_unnil(empty)
prval EQADDR() = eqaddr_make{buf,buf2+fill}()
prval _ = view@(buf) := l
in 0 end
On Apr 14, 2015, at 10:30 PM, gmhwxi <gmh...@gmail.com> wrote:>>Ah, OK. Was there a reason you kept the t: t@ype in the declaration but not the buf: addr?You are right. The following code typechecks:
I prefer to keep quantifiers over type variables at the front.>>Hmm, but the type of partial is partial_buf ( byte, 0, 10, buf ), so empty has to be empty, right?implement main () = let
var buf = @[byte][10]()
prval pfbuf = view@(buf)
prval pfemp = array_v_nil{byte}{buf}()
prval partial = partial_buf{byte}{0,10}{..}(pfemp, pfbuf)
prval partial_buf{..}{fill,total}{buf2}(empty, l) = partial
prval _ = array_v_unnil(empty)
prval EQADDR() = eqaddr_make{buf,buf2+fill}()
prval _ = view@(buf) := l
in 0 end
I really don't know how to explain this. Basically, when you put a proof of some view
into view@(buf), the typechecker expects the view to be of the form T@buf (it is not
okay even if you have the form T@(buf+0)).
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/9bb0a533-36a5-4adc-bd25-e11329408ebe%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/bb963b0b-6812-46e1-a1b0-66622c0dc65c%40googlegroups.com.