# Constructor pattern cannot be assigned the type

**URL:** <https://discourse.ats-lang.org/t/constructor-pattern-cannot-be-assigned-the-type/468>\
**Category:** Google Group\
**Created:** [January 13, 2014, 4:18am UTC](https://discourse.ats-lang.org/t/constructor-pattern-cannot-be-assigned-the-type/468 "2014-01-13T04:18:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brandon\_Barker](https://sea1.discourse-cdn.com/flex019/user_avatar/discourse.ats-lang.org/brandon_barker/32/61_2.png) [@Brandon\_Barker](https://discourse.ats-lang.org/u/Brandon_Barker)\
**Post date:** [January 13, 2014, 4:18am UTC](https://discourse.ats-lang.org/t/constructor-pattern-cannot-be-assigned-the-type/468/1 "2014-01-13T04:18:57Z")

</div>

I understand (but not completely how) dataviewtypes have changed in ATS2.  
That aside, there are likely numerous errors here that I should not be  
having if I remembered everything I learned in ATS1 being that the output  
of patsopt reminds me of some of my worst C++ compiler errors involving  
heavy use of template libraries :).

I will just show what I have for the first part:

.sats:  
fun{a:t0p}  
linset\_union (xs1: set(INV(a)), xs2: set(INV(a))): List0\_vt (a)

.dats:  
implement{a}  
linset\_union  
(xs1, xs2) = let  
//  
fun aux // non-tail-recursive  
{n1,n2:nat} .\<n1+n2\>.  
(  
xs1: list (a, n1), xs2: list (a, n2)  
) :\<\> List0\_vt (a) = let // should be able to return e.g. listGte\_vt(a, n3)  
in // where n3 \>= min(n1, n2)  
//  
case xs1 of  
| list\_vt\_cons  
(x1, xs11) =\>

Highlighted part gives the error:  
/home/brand\_000/ATS-Postiats/libats/DATS/linset\_listord.dats:  
10284(line=534, offs=3) – 10311(line=535, offs=15): error(3): the  
constructor pattern cannot be assigned the type  
[S2Eapp(S2Ecst(list\_t0ype\_int\_type); S2Evar(a(7153)), S2Evar(n1(7155)))].  
/home/brand\_000/ATS-Postiats/libats/DATS/linset\_listord.dats:  
10338(line=538, offs=5) – 10361(line=538, offs=28): error(3): the  
constructor pattern cannot be assigned the type  
[S2Eapp(S2Ecst(list\_t0ype\_int\_type); S2Evar(a(7153)), S2Evar(n2(7156)))].

---

<div class="post-metadata">

**Author:** ![Brandon\_Barker](https://sea1.discourse-cdn.com/flex019/user_avatar/discourse.ats-lang.org/brandon_barker/32/61_2.png) [@Brandon\_Barker](https://discourse.ats-lang.org/u/Brandon_Barker)\
**Post date:** [January 16, 2014, 5:01pm UTC](https://discourse.ats-lang.org/t/constructor-pattern-cannot-be-assigned-the-type/468/2 "2014-01-16T17:01:54Z")

</div>

I’m still having some trouble getting used to linear datatypes in ATS2,  
though it looks like it will be a bit more straightforward than in ATS1.  
Here’s an attempt for list\_union; trouble seems to occur around free@ -  
something to do with making the unfolded dataviewtypes inaccessible, but  
i’m not sure how to get around that.

One other thing I’m unsure about is what is going on with bindings like:

val xs11 = xs11

full code at:

> **[Comparing githwxi:master...bbarker:master · githwxi/ATS-Postiats](https://github.com/githwxi/ATS-Postiats/compare/master...bbarker:ATS-Postiats:master)**
>
> ATS2: Unleashing the Potentials of Types and Templates - Comparing githwxi:master...bbarker:master · githwxi/ATS-Postiats

(\* \*\*\*\*\*\* \*\*\*\*\*\* \*)  
implement{a}  
linset\_union  
(xs1, xs2) = let  
//  
viewtypedef res = List\_vt (a)  
fun loop  
{n1,n2:nat} .\<n1+n2\>. (  
xs1: list\_vt (a, n1), xs2: list\_vt (a, n2), res: &res? \>\> res  
) :\<!wrt,cloref\> void =  
case+ xs1 of  
| @list\_vt\_cons (x1, xs11) =\> (  
case+ xs2 of  
| @list\_vt\_cons (x2, xs21) =\> let  
val sgn = compare\_elt\_elt (x1, x2)  
in  
if sgn \< 0 then let  
//val () = $showtype(xs11)  
//val xs11 = xs11 // What does this do?  
//val () = $showtype(xs11)  
prval () = fold@ {a} (xs2)  
val () = loop (xs11, xs2, xs11)  
prval () = fold@ {a} (xs1)  
in  
res := xs1  
end else if sgn \> 0 then let  
//val xs21 = xs21  
prval () = fold@ {a} (xs1)  
val () = loop (xs1, xs21, xs21)  
prval () = fold@ (xs2)  
in  
res := xs2  
end else let // x1 = x2  
//val xs11 = xs11  
//val xs21 = xs21  
val () = free@ {a}{0} (xs2)  
val () = loop (xs11, xs21, xs21)  
prval () = fold@ (xs1)  
in  
res := xs1  
end // end of [if]  
end // end of [list\_vt\_cons]  
| ~list\_vt\_nil () =\> (fold@ (xs1); res := xs1)  
) // end of [list\_vt\_cons]  
| ~list\_vt\_nil () =\> (res := xs2)  
// end of [loop]  
var res: res // uninitialized  
val () = loop (xs1, xs2, res)  
in  
resOn Monday, January 13, 2014 9:38:30 PM UTC-5, Brandon Barker wrote:

 

> That’ll do it … typo (due to copy/paste from funset).
> 
> On Monday, January 13, 2014 12:22:01 AM UTC-5, gmhwxi wrote:
> 
> > xs1 is given the type list(a) but the constructor list\_vt\_cons is used;  
> > list\_cons should be used instead.
> > 
> > On Sunday, January 12, 2014 11:18:57 PM UTC-5, Brandon Barker wrote:
> > 
> > > I understand (but not completely how) dataviewtypes have changed in  
> > > ATS2. That aside, there are likely numerous errors here that I should not  
> > > be having if I remembered everything I learned in ATS1 being that the  
> > > output of patsopt reminds me of some of my worst C++ compiler errors  
> > > involving heavy use of template libraries :).
> > > 
> > > I will just show what I have for the first part:
> > > 
> > > .sats:  
> > > fun{a:t0p}  
> > > linset\_union (xs1: set(INV(a)), xs2: set(INV(a))): List0\_vt (a)
> > > 
> > > .dats:  
> > > implement{a}  
> > > linset\_union  
> > > (xs1, xs2) = let  
> > > //  
> > > fun aux // non-tail-recursive  
> > > {n1,n2:nat} .\<n1+n2\>.  
> > > (  
> > > xs1: list (a, n1), xs2: list (a, n2)  
> > > ) :\<\> List0\_vt (a) = let // should be able to return e.g. listGte\_vt(a,  
> > > n3)  
> > > in // where n3 \>= min(n1, n2)  
> > > //  
> > > case xs1 of  
> > > | list\_vt\_cons  
> > > (x1, xs11) =\>
> > > 
> > > Highlighted part gives the error:  
> > > /home/brand\_000/ATS-Postiats/libats/DATS/linset\_listord.dats:  
> > > 10284(line=534, offs=3) – 10311(line=535, offs=15): error(3): the  
> > > constructor pattern cannot be assigned the type  
> > > [S2Eapp(S2Ecst(list\_t0ype\_int\_type); S2Evar(a(7153)), S2Evar(n1(7155)))].  
> > > /home/brand\_000/ATS-Postiats/libats/DATS/linset\_listord.dats:  
> > > 10338(line=538, offs=5) – 10361(line=538, offs=28): error(3): the  
> > > constructor pattern cannot be assigned the type  
> > > [S2Eapp(S2Ecst(list\_t0ype\_int\_type); S2Evar(a(7153)), S2Evar(n2(7156)))].

---

<div class="post-metadata">

**Author:** ![Brandon\_Barker](https://sea1.discourse-cdn.com/flex019/user_avatar/discourse.ats-lang.org/brandon_barker/32/61_2.png) [@Brandon\_Barker](https://discourse.ats-lang.org/u/Brandon_Barker)\
**Post date:** [January 14, 2014, 2:38am UTC](https://discourse.ats-lang.org/t/constructor-pattern-cannot-be-assigned-the-type/468/3 "2014-01-14T02:38:30Z")

</div>

That’ll do it … typo (due to copy/paste from funset).On Monday, January 13, 2014 12:22:01 AM UTC-5, gmhwxi wrote:

> xs1 is given the type list(a) but the constructor list\_vt\_cons is used;  
> list\_cons should be used instead.
> 
> On Sunday, January 12, 2014 11:18:57 PM UTC-5, Brandon Barker wrote:
> 
> > I understand (but not completely how) dataviewtypes have changed in ATS2.  
> > That aside, there are likely numerous errors here that I should not be  
> > having if I remembered everything I learned in ATS1 being that the output  
> > of patsopt reminds me of some of my worst C++ compiler errors involving  
> > heavy use of template libraries :).
> > 
> > I will just show what I have for the first part:
> > 
> > .sats:  
> > fun{a:t0p}  
> > linset\_union (xs1: set(INV(a)), xs2: set(INV(a))): List0\_vt (a)
> > 
> > .dats:  
> > implement{a}  
> > linset\_union  
> > (xs1, xs2) = let  
> > //  
> > fun aux // non-tail-recursive  
> > {n1,n2:nat} .\<n1+n2\>.  
> > (  
> > xs1: list (a, n1), xs2: list (a, n2)  
> > ) :\<\> List0\_vt (a) = let // should be able to return e.g. listGte\_vt(a,  
> > n3)  
> > in // where n3 \>= min(n1, n2)  
> > //  
> > case xs1 of  
> > | list\_vt\_cons  
> > (x1, xs11) =\>
> > 
> > Highlighted part gives the error:  
> > /home/brand\_000/ATS-Postiats/libats/DATS/linset\_listord.dats:  
> > 10284(line=534, offs=3) – 10311(line=535, offs=15): error(3): the  
> > constructor pattern cannot be assigned the type  
> > [S2Eapp(S2Ecst(list\_t0ype\_int\_type); S2Evar(a(7153)), S2Evar(n1(7155)))].  
> > /home/brand\_000/ATS-Postiats/libats/DATS/linset\_listord.dats:  
> > 10338(line=538, offs=5) – 10361(line=538, offs=28): error(3): the  
> > constructor pattern cannot be assigned the type  
> > [S2Eapp(S2Ecst(list\_t0ype\_int\_type); S2Evar(a(7153)), S2Evar(n2(7156)))].

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [January 16, 2014, 10:16pm UTC](https://discourse.ats-lang.org/t/constructor-pattern-cannot-be-assigned-the-type/468/4 "2014-01-16T22:16:33Z")

</div>

See the following code:

case+ xs1 of  
| @list\_vt\_cons (x1, xs11) =\> (  
case+ xs2 of  
| @list\_vt\_cons (x2, xs21) =\> let  
val sgn = compare\_elt\_elt (x1, x2)  
in  
if sgn \< 0 then let  
val xs11\_ = xs11  
prval () = fold@ {a} (xs2)  
val () = loop (xs11\_, xs2, xs11)  
prval () = fold@ {a} (xs1)  
in  
res := xs1  
end else if sgn \> 0 then let  
val xs21\_ = xs21  
prval () = fold@ {a} (xs1)  
val () = loop (xs1, xs21\_, xs21)  
prval () = fold@ (xs2)  
in  
res := xs2  
end else let // x1 = x2  
val xs11\_ = xs11  
val xs21\_ = xs21  
val () = free@ {a}{0} (xs2)  
val () = loop (xs11\_, xs21\_, xs11)  
prval () = fold@ (xs1)  
in  
res := xs1  
end // end of [if]  
end // end of [list\_vt\_cons]  
| ~list\_vt\_nil () =\> (fold@ (xs1); res := xs1)  
) // end of [list\_vt\_cons]  
| ~list\_vt\_nil () =\> (res := xs2)On Thursday, January 16, 2014 12:02:44 PM UTC-5, Brandon Barker wrote:

 

> left off an “end” at the end of the pasted implementation.
> 
>  
> 
> On Thursday, January 16, 2014 12:01:54 PM UTC-5, Brandon Barker wrote:
> 
>  
> 
> > I’m still having some trouble getting used to linear datatypes in ATS2,  
> > though it looks like it will be a bit more straightforward than in ATS1.  
> > Here’s an attempt for list\_union; trouble seems to occur around free@ -  
> > something to do with making the unfolded dataviewtypes inaccessible, but  
> > i’m not sure how to get around that.
> > 
> >  
> > 
> > One other thing I’m unsure about is what is going on with bindings like:
> > 
> >  
> > 
> > val xs11 = xs11
> > 
> >  
> > 
> > full code at:  
> > [Comparing githwxi:master...bbarker:master · githwxi/ATS-Postiats · GitHub](https://github.com/bbarker/ATS-Postiats/compare/githwxi:master...master#)
> > 
> > (\* \*\*\*\*\*\* \*\*\*\*\*\* \*)  
> > implement{a}  
> > linset\_union  
> > (xs1, xs2) = let  
> > //  
> > viewtypedef res = List\_vt (a)  
> > fun loop  
> > {n1,n2:nat} .\<n1+n2\>. (  
> > xs1: list\_vt (a, n1), xs2: list\_vt (a, n2), res: &res? \>\> res  
> > ) :\<!wrt,cloref\> void =  
> > case+ xs1 of  
> > | @list\_vt\_cons (x1, xs11) =\> (  
> > case+ xs2 of  
> > | @list\_vt\_cons (x2, xs21) =\> let  
> > val sgn = compare\_elt\_elt (x1, x2)  
> > in  
> > if sgn \< 0 then let  
> > //val () = $showtype(xs11)  
> > //val xs11 = xs11 // What does this do?  
> > //val () = $showtype(xs11)  
> > prval () = fold@ {a} (xs2)  
> > val () = loop (xs11, xs2, xs11)  
> > prval () = fold@ {a} (xs1)  
> > in  
> > res := xs1  
> > end else if sgn \> 0 then let  
> > //val xs21 = xs21  
> > prval () = fold@ {a} (xs1)  
> > val () = loop (xs1, xs21, xs21)  
> > prval () = fold@ (xs2)  
> > in  
> > res := xs2  
> > end else let // x1 = x2  
> > //val xs11 = xs11  
> > //val xs21 = xs21  
> > val () = free@ {a}{0} (xs2)  
> > val () = loop (xs11, xs21, xs21)  
> > prval () = fold@ (xs1)  
> > in  
> > res := xs1  
> > end // end of [if]  
> > end // end of [list\_vt\_cons]  
> > | ~list\_vt\_nil () =\> (fold@ (xs1); res := xs1)  
> > ) // end of [list\_vt\_cons]  
> > | ~list\_vt\_nil () =\> (res := xs2)  
> > // end of [loop]  
> > var res: res // uninitialized  
> > val () = loop (xs1, xs2, res)  
> > in  
> > res
> > 
> >  
> > 
> > On Monday, January 13, 2014 9:38:30 PM UTC-5, Brandon Barker wrote:
> > 
> >  
> > 
> > > That’ll do it … typo (due to copy/paste from funset).
> > > 
> > > On Monday, January 13, 2014 12:22:01 AM UTC-5, gmhwxi wrote:
> > > 
> > > > xs1 is given the type list(a) but the constructor list\_vt\_cons is used;  
> > > > list\_cons should be used instead.
> > > > 
> > > > On Sunday, January 12, 2014 11:18:57 PM UTC-5, Brandon Barker wrote:
> > > > 
> > > > > I understand (but not completely how) dataviewtypes have changed in  
> > > > > ATS2. That aside, there are likely numerous errors here that I should not  
> > > > > be having if I remembered everything I learned in ATS1 being that the  
> > > > > output of patsopt reminds me of some of my worst C++ compiler errors  
> > > > > involving heavy use of template libraries :).
> > > > > 
> > > > > I will just show what I have for the first part:
> > > > > 
> > > > > .sats:  
> > > > > fun{a:t0p}  
> > > > > linset\_union (xs1: set(INV(a)), xs2: set(INV(a))): List0\_vt (a)
> > > > > 
> > > > > .dats:  
> > > > > implement{a}  
> > > > > linset\_union  
> > > > > (xs1, xs2) = let  
> > > > > //  
> > > > > fun aux // non-tail-recursive  
> > > > > {n1,n2:nat} .\<n1+n2\>.  
> > > > > (  
> > > > > xs1: list (a, n1), xs2: list (a, n2)  
> > > > > ) :\<\> List0\_vt (a) = let // should be able to return e.g.  
> > > > > listGte\_vt(a, n3)  
> > > > > in // where n3 \>= min(n1, n2)  
> > > > > //  
> > > > > case xs1 of  
> > > > > | list\_vt\_cons  
> > > > > (x1, xs11) =\>
> > > > > 
> > > > > Highlighted part gives the error:  
> > > > > /home/brand\_000/ATS-Postiats/libats/DATS/linset\_listord.dats:  
> > > > > 10284(line=534, offs=3) – 10311(line=535, offs=15): error(3): the  
> > > > > constructor pattern cannot be assigned the type  
> > > > > [S2Eapp(S2Ecst(list\_t0ype\_int\_type); S2Evar(a(7153)), S2Evar(n1(7155)))].  
> > > > > /home/brand\_000/ATS-Postiats/libats/DATS/linset\_listord.dats:  
> > > > > 10338(line=538, offs=5) – 10361(line=538, offs=28): error(3): the  
> > > > > constructor pattern cannot be assigned the type  
> > > > > [S2Eapp(S2Ecst(list\_t0ype\_int\_type); S2Evar(a(7153)), S2Evar(n2(7156)))].

---

<div class="post-metadata">

**Author:** ![Brandon\_Barker](https://sea1.discourse-cdn.com/flex019/user_avatar/discourse.ats-lang.org/brandon_barker/32/61_2.png) [@Brandon\_Barker](https://discourse.ats-lang.org/u/Brandon_Barker)\
**Post date:** [January 16, 2014, 5:02pm UTC](https://discourse.ats-lang.org/t/constructor-pattern-cannot-be-assigned-the-type/468/5 "2014-01-16T17:02:44Z")

</div>

left off an “end” at the end of the pasted implementation.On Thursday, January 16, 2014 12:01:54 PM UTC-5, Brandon Barker wrote:

> I’m still having some trouble getting used to linear datatypes in ATS2,  
> though it looks like it will be a bit more straightforward than in ATS1.  
> Here’s an attempt for list\_union; trouble seems to occur around free@ -  
> something to do with making the unfolded dataviewtypes inaccessible, but  
> i’m not sure how to get around that.
> 
> One other thing I’m unsure about is what is going on with bindings like:
> 
> val xs11 = xs11
> 
> full code at:  
> [Comparing githwxi:master...bbarker:master · githwxi/ATS-Postiats · GitHub](https://github.com/bbarker/ATS-Postiats/compare/githwxi:master...master#)
> 
> (\* \*\*\*\*\*\* \*\*\*\*\*\* \*)  
> implement{a}  
> linset\_union  
> (xs1, xs2) = let  
> //  
> viewtypedef res = List\_vt (a)  
> fun loop  
> {n1,n2:nat} .\<n1+n2\>. (  
> xs1: list\_vt (a, n1), xs2: list\_vt (a, n2), res: &res? \>\> res  
> ) :\<!wrt,cloref\> void =  
> case+ xs1 of  
> | @list\_vt\_cons (x1, xs11) =\> (  
> case+ xs2 of  
> | @list\_vt\_cons (x2, xs21) =\> let  
> val sgn = compare\_elt\_elt (x1, x2)  
> in  
> if sgn \< 0 then let  
> //val () = $showtype(xs11)  
> //val xs11 = xs11 // What does this do?  
> //val () = $showtype(xs11)  
> prval () = fold@ {a} (xs2)  
> val () = loop (xs11, xs2, xs11)  
> prval () = fold@ {a} (xs1)  
> in  
> res := xs1  
> end else if sgn \> 0 then let  
> //val xs21 = xs21  
> prval () = fold@ {a} (xs1)  
> val () = loop (xs1, xs21, xs21)  
> prval () = fold@ (xs2)  
> in  
> res := xs2  
> end else let // x1 = x2  
> //val xs11 = xs11  
> //val xs21 = xs21  
> val () = free@ {a}{0} (xs2)  
> val () = loop (xs11, xs21, xs21)  
> prval () = fold@ (xs1)  
> in  
> res := xs1  
> end // end of [if]  
> end // end of [list\_vt\_cons]  
> | ~list\_vt\_nil () =\> (fold@ (xs1); res := xs1)  
> ) // end of [list\_vt\_cons]  
> | ~list\_vt\_nil () =\> (res := xs2)  
> // end of [loop]  
> var res: res // uninitialized  
> val () = loop (xs1, xs2, res)  
> in  
> res
> 
>  
> 
> On Monday, January 13, 2014 9:38:30 PM UTC-5, Brandon Barker wrote:
> 
>  
> 
> > That’ll do it … typo (due to copy/paste from funset).
> > 
> > On Monday, January 13, 2014 12:22:01 AM UTC-5, gmhwxi wrote:
> > 
> > > xs1 is given the type list(a) but the constructor list\_vt\_cons is used;  
> > > list\_cons should be used instead.
> > > 
> > > On Sunday, January 12, 2014 11:18:57 PM UTC-5, Brandon Barker wrote:
> > > 
> > > > I understand (but not completely how) dataviewtypes have changed in  
> > > > ATS2. That aside, there are likely numerous errors here that I should not  
> > > > be having if I remembered everything I learned in ATS1 being that the  
> > > > output of patsopt reminds me of some of my worst C++ compiler errors  
> > > > involving heavy use of template libraries :).
> > > > 
> > > > I will just show what I have for the first part:
> > > > 
> > > > .sats:  
> > > > fun{a:t0p}  
> > > > linset\_union (xs1: set(INV(a)), xs2: set(INV(a))): List0\_vt (a)
> > > > 
> > > > .dats:  
> > > > implement{a}  
> > > > linset\_union  
> > > > (xs1, xs2) = let  
> > > > //  
> > > > fun aux // non-tail-recursive  
> > > > {n1,n2:nat} .\<n1+n2\>.  
> > > > (  
> > > > xs1: list (a, n1), xs2: list (a, n2)  
> > > > ) :\<\> List0\_vt (a) = let // should be able to return e.g.  
> > > > listGte\_vt(a, n3)  
> > > > in // where n3 \>= min(n1, n2)  
> > > > //  
> > > > case xs1 of  
> > > > | list\_vt\_cons  
> > > > (x1, xs11) =\>
> > > > 
> > > > Highlighted part gives the error:  
> > > > /home/brand\_000/ATS-Postiats/libats/DATS/linset\_listord.dats:  
> > > > 10284(line=534, offs=3) – 10311(line=535, offs=15): error(3): the  
> > > > constructor pattern cannot be assigned the type  
> > > > [S2Eapp(S2Ecst(list\_t0ype\_int\_type); S2Evar(a(7153)), S2Evar(n1(7155)))].  
> > > > /home/brand\_000/ATS-Postiats/libats/DATS/linset\_listord.dats:  
> > > > 10338(line=538, offs=5) – 10361(line=538, offs=28): error(3): the  
> > > > constructor pattern cannot be assigned the type  
> > > > [S2Eapp(S2Ecst(list\_t0ype\_int\_type); S2Evar(a(7153)), S2Evar(n2(7156)))].

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [January 13, 2014, 5:22am UTC](https://discourse.ats-lang.org/t/constructor-pattern-cannot-be-assigned-the-type/468/6 "2014-01-13T05:22:01Z")

</div>

xs1 is given the type list(a) but the constructor list\_vt\_cons is used;  
list\_cons should be used instead.On Sunday, January 12, 2014 11:18:57 PM UTC-5, Brandon Barker wrote:

> I understand (but not completely how) dataviewtypes have changed in ATS2.  
> That aside, there are likely numerous errors here that I should not be  
> having if I remembered everything I learned in ATS1 being that the output  
> of patsopt reminds me of some of my worst C++ compiler errors involving  
> heavy use of template libraries :).
> 
> I will just show what I have for the first part:
> 
> .sats:  
> fun{a:t0p}  
> linset\_union (xs1: set(INV(a)), xs2: set(INV(a))): List0\_vt (a)
> 
> .dats:  
> implement{a}  
> linset\_union  
> (xs1, xs2) = let  
> //  
> fun aux // non-tail-recursive  
> {n1,n2:nat} .\<n1+n2\>.  
> (  
> xs1: list (a, n1), xs2: list (a, n2)  
> ) :\<\> List0\_vt (a) = let // should be able to return e.g. listGte\_vt(a,  
> n3)  
> in // where n3 \>= min(n1, n2)  
> //  
> case xs1 of  
> | list\_vt\_cons  
> (x1, xs11) =\>
> 
> Highlighted part gives the error:  
> /home/brand\_000/ATS-Postiats/libats/DATS/linset\_listord.dats:  
> 10284(line=534, offs=3) – 10311(line=535, offs=15): error(3): the  
> constructor pattern cannot be assigned the type  
> [S2Eapp(S2Ecst(list\_t0ype\_int\_type); S2Evar(a(7153)), S2Evar(n1(7155)))].  
> /home/brand\_000/ATS-Postiats/libats/DATS/linset\_listord.dats:  
> 10338(line=538, offs=5) – 10361(line=538, offs=28): error(3): the  
> constructor pattern cannot be assigned the type  
> [S2Eapp(S2Ecst(list\_t0ype\_int\_type); S2Evar(a(7153)), S2Evar(n2(7156)))].

---

<div class="post-metadata">

**Author:** ![Brandon\_Barker](https://sea1.discourse-cdn.com/flex019/user_avatar/discourse.ats-lang.org/brandon_barker/32/61_2.png) [@Brandon\_Barker](https://discourse.ats-lang.org/u/Brandon_Barker)\
**Post date:** [January 16, 2014, 11:36pm UTC](https://discourse.ats-lang.org/t/constructor-pattern-cannot-be-assigned-the-type/468/7 "2014-01-16T23:36:10Z")

</div>

Thanks, I think I see: if RHS is a reference to a value of some viewtype,  
val LHS = RHS

then LHS is the value of that viewtype itself. However, $showtype was not  
very clear on this, but the type of xs11 did seem to change after the val  
statement, but I wouldn’t that is correct.

$showtype(xs11) //says something about the viewtype (list\_vt)  
val xs11\_ = xs11  
$showtype(xs11\_) //says something about the viewtype  
$showtype(xs11) //also says something about the viewtype

I think in ATS1, we had to do:  
val LHS = !RHS.On Thursday, January 16, 2014 5:16:33 PM UTC-5, gmhwxi wrote:

> See the following code:
> 
> case+ xs1 of  
> | @list\_vt\_cons (x1, xs11) =\> (  
> case+ xs2 of  
> | @list\_vt\_cons (x2, xs21) =\> let  
> val sgn = compare\_elt\_elt (x1, x2)  
> in  
> if sgn \< 0 then let  
> val xs11\_ = xs11  
> prval () = fold@ {a} (xs2)  
> val () = loop (xs11\_, xs2, xs11)  
> prval () = fold@ {a} (xs1)  
> in  
> res := xs1  
> end else if sgn \> 0 then let  
> val xs21\_ = xs21  
> prval () = fold@ {a} (xs1)  
> val () = loop (xs1, xs21\_, xs21)  
> prval () = fold@ (xs2)  
> in  
> res := xs2  
> end else let // x1 = x2  
> val xs11\_ = xs11  
> val xs21\_ = xs21  
> val () = free@ {a}{0} (xs2)  
> val () = loop (xs11\_, xs21\_, xs11)  
> prval () = fold@ (xs1)  
> in  
> res := xs1  
> end // end of [if]  
> end // end of [list\_vt\_cons]  
> | ~list\_vt\_nil () =\> (fold@ (xs1); res := xs1)  
> ) // end of [list\_vt\_cons]  
> | ~list\_vt\_nil () =\> (res := xs2)
> 
>  
> 
> On Thursday, January 16, 2014 12:02:44 PM UTC-5, Brandon Barker wrote:
> 
>  
> 
> > left off an “end” at the end of the pasted implementation.
> > 
> >  
> > 
> > On Thursday, January 16, 2014 12:01:54 PM UTC-5, Brandon Barker wrote:
> > 
> >  
> > 
> > > I’m still having some trouble getting used to linear datatypes in ATS2,  
> > > though it looks like it will be a bit more straightforward than in ATS1.  
> > > Here’s an attempt for list\_union; trouble seems to occur around free@ -  
> > > something to do with making the unfolded dataviewtypes inaccessible, but  
> > > i’m not sure how to get around that.
> > > 
> > >  
> > > 
> > > One other thing I’m unsure about is what is going on with bindings like:
> > > 
> > >  
> > > 
> > > val xs11 = xs11
> > > 
> > >  
> > > 
> > > full code at:  
> > > [Comparing githwxi:master...bbarker:master · githwxi/ATS-Postiats · GitHub](https://github.com/bbarker/ATS-Postiats/compare/githwxi:master...master#)
> > > 
> > > (\* \*\*\*\*\*\* \*\*\*\*\*\* \*)  
> > > implement{a}  
> > > linset\_union  
> > > (xs1, xs2) = let  
> > > //  
> > > viewtypedef res = List\_vt (a)  
> > > fun loop  
> > > {n1,n2:nat} .\<n1+n2\>. (  
> > > xs1: list\_vt (a, n1), xs2: list\_vt (a, n2), res: &res? \>\> res  
> > > ) :\<!wrt,cloref\> void =  
> > > case+ xs1 of  
> > > | @list\_vt\_cons (x1, xs11) =\> (  
> > > case+ xs2 of  
> > > | @list\_vt\_cons (x2, xs21) =\> let  
> > > val sgn = compare\_elt\_elt (x1, x2)  
> > > in  
> > > if sgn \< 0 then let  
> > > //val () = $showtype(xs11)  
> > > //val xs11 = xs11 // What does this do?  
> > > //val () = $showtype(xs11)  
> > > prval () = fold@ {a} (xs2)  
> > > val () = loop (xs11, xs2, xs11)  
> > > prval () = fold@ {a} (xs1)  
> > > in  
> > > res := xs1  
> > > end else if sgn \> 0 then let  
> > > //val xs21 = xs21  
> > > prval () = fold@ {a} (xs1)  
> > > val () = loop (xs1, xs21, xs21)  
> > > prval () = fold@ (xs2)  
> > > in  
> > > res := xs2  
> > > end else let // x1 = x2  
> > > //val xs11 = xs11  
> > > //val xs21 = xs21  
> > > val () = free@ {a}{0} (xs2)  
> > > val () = loop (xs11, xs21, xs21)  
> > > prval () = fold@ (xs1)  
> > > in  
> > > res := xs1  
> > > end // end of [if]  
> > > end // end of [list\_vt\_cons]  
> > > | ~list\_vt\_nil () =\> (fold@ (xs1); res := xs1)  
> > > ) // end of [list\_vt\_cons]  
> > > | ~list\_vt\_nil () =\> (res := xs2)  
> > > // end of [loop]  
> > > var res: res // uninitialized  
> > > val () = loop (xs1, xs2, res)  
> > > in  
> > > res
> > > 
> > >  
> > > 
> > > On Monday, January 13, 2014 9:38:30 PM UTC-5, Brandon Barker wrote:
> > > 
> > >  
> > > 
> > > > That’ll do it … typo (due to copy/paste from funset).
> > > > 
> > > > On Monday, January 13, 2014 12:22:01 AM UTC-5, gmhwxi wrote:
> > > > 
> > > > > xs1 is given the type list(a) but the constructor list\_vt\_cons is  
> > > > > used; list\_cons should be used instead.
> > > > > 
> > > > > On Sunday, January 12, 2014 11:18:57 PM UTC-5, Brandon Barker wrote:
> > > > > 
> > > > > > I understand (but not completely how) dataviewtypes have changed in  
> > > > > > ATS2. That aside, there are likely numerous errors here that I should not  
> > > > > > be having if I remembered everything I learned in ATS1 being that the  
> > > > > > output of patsopt reminds me of some of my worst C++ compiler errors  
> > > > > > involving heavy use of template libraries :).
> > > > > > 
> > > > > > I will just show what I have for the first part:
> > > > > > 
> > > > > > .sats:  
> > > > > > fun{a:t0p}  
> > > > > > linset\_union (xs1: set(INV(a)), xs2: set(INV(a))): List0\_vt (a)
> > > > > > 
> > > > > > .dats:  
> > > > > > implement{a}  
> > > > > > linset\_union  
> > > > > > (xs1, xs2) = let  
> > > > > > //  
> > > > > > fun aux // non-tail-recursive  
> > > > > > {n1,n2:nat} .\<n1+n2\>.  
> > > > > > (  
> > > > > > xs1: list (a, n1), xs2: list (a, n2)  
> > > > > > ) :\<\> List0\_vt (a) = let // should be able to return e.g.  
> > > > > > listGte\_vt(a, n3)  
> > > > > > in // where n3 \>= min(n1, n2)  
> > > > > > //  
> > > > > > case xs1 of  
> > > > > > | list\_vt\_cons  
> > > > > > (x1, xs11) =\>
> > > > > > 
> > > > > > Highlighted part gives the error:  
> > > > > > /home/brand\_000/ATS-Postiats/libats/DATS/linset\_listord.dats:  
> > > > > > 10284(line=534, offs=3) – 10311(line=535, offs=15): error(3): the  
> > > > > > constructor pattern cannot be assigned the type  
> > > > > > [S2Eapp(S2Ecst(list\_t0ype\_int\_type); S2Evar(a(7153)), S2Evar(n1(7155)))].  
> > > > > > /home/brand\_000/ATS-Postiats/libats/DATS/linset\_listord.dats:  
> > > > > > 10338(line=538, offs=5) – 10361(line=538, offs=28): error(3): the  
> > > > > > constructor pattern cannot be assigned the type  
> > > > > > [S2Eapp(S2Ecst(list\_t0ype\_int\_type); S2Evar(a(7153)), S2Evar(n2(7156)))].
