My current, not so successful try is to define result_vt:

datavtype result_vt (av: view, a:t@ype+, bv: view, b:t@ype+) =
  | Success_vt(av,a, bv, b) of (av | a)
  | Failure_vt(av,a, bv, b) of (bv | b)

and function's ftype:
fn
  recvfrom
  {l: addr} {n: pos}
  ( buf_pf: array_v(char?, l, n)
  | socket_fd: int
  , buf: ptr l
  , sz: size_t n
  , flags: int
  , src_addr: &sockaddr_in_struct?
  , addr_sz: &size_t
  ): [m:pos | m <= n] result_vt( (array_v(char,l,m), array_v(char?,l+m,
n-m)), (sockaddr_in_struct, size_t m), array_v(char?,l,n), void) =
  let
    val ret = g1ofg0( $extfcall(ssize_t, "recvfrom", socket_fd, buf, sz,
flags, addr@src_addr, addr@addr_sz))
  in
  if ret < 1
  then Failure_vt( buf_pf | ())
  else Success_vt( (answer_pf, rest_buf_pf) | (src_addr, ret) (*complains
on this line *) ) where {
    extern praxi unnil{v:viewt0ype} ( p: &v? >> v): void
    prval () = unnil(src_addr)
    val (answer_pf, rest_buf_pf) = array_v_split( buf_pf)
  }
  end

but compiler is not happy with it, giving me errors:
error(3): the dynamic expression cannot be assigned the type [S2EVar(5259)].
error(3): mismatch of sorts in unification:
The sort of variable is: S2RTbas(S2RTBASimp(9; t@ype+))
The sort of solution is: S2RTbas(S2RTBASimp(3; viewt0ype))
error(3): mismatch of static terms (tyleq):
The actual term is: S2Etyrec(flt0; npf=-1; 0=S2EVar(5253),
1=S2Eapp(S2Ecst(g1int_int_t0ype); S2Eextkind(atstype_ssize),
S2Evar(i$8638$8639(14396))))
The needed term is: S2EVar(5259)


пт, 10 июл. 2020 г. в 12:47, [email protected] <[email protected]>:

>
> Hi again :)
>
> I have function
>
> fn
>   recvfrom
>   {l: addr} {n: pos}
>   ( buf_pf: array_v(char?, l, n)
>   | socket_fd: int
>   , buf: ptr l
>   , sz: size_t n
>   , flags: int
>   , src_addr: &sockaddr_in_struct?
>   , addr_sz: &size_t
>   ): [m:int] ssize_t int
>
> I want to change it's return type, such that in case of success, it should
> split buf_pf on 2 arrays: initialized and unintialized one and src_addr to
> became initialized.
> In case of failure, I want to return buf_pf and src_addr of the same view
> (uninitialized)
>
> How can I do it properly?
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "ats-lang-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ats-lang-users/O-KlWtJqq1I/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ats-lang-users/e013b1ec-d89b-49f9-b79a-46803b480bcen%40googlegroups.com
> <https://groups.google.com/d/msgid/ats-lang-users/e013b1ec-d89b-49f9-b79a-46803b480bcen%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/CAHjn2Ky_WVC2r4y8h-EH-YX_WA-3t7O9J9z33SKwc1pvJB%2BOKw%40mail.gmail.com.

Reply via email to