Re: [ats-lang-users] strange compiler error message
Unleashing the potentials of types and templates
Status: Beta
Brought to you by:
ats-hwxi
From: Guillaume B. <gui...@gm...> - 2010-02-02 02:43:59
|
Hi, The type int -> int means any function taking integers to integers, possibly non terminating, with side effects and/or raising an exception. The type int -<> int means that all side effects are disallowed : the function must terminate, without raising any exception, writing something on somewhere nor modifying some reference or array. The type int -<fun> int is the same as int -<> int, because 'fun' means that this is a normal function (this is the default), and because tagged arrow disallow every side effect by default. Now you could think that your code should compile because the function id terminate and has obviously no side effect. But when you write fun id(x:int):int = x:int, you tell the compiler that the function id is a normal function and can have side effects. The compiler agrees with that, and what he remembers is that id is of type int -> int (or int -<fun1> int, which is the same, the 1 meaning that any side effect is allowed), and doesn’t accept it as a value for bar, because it is expected only pure and terminating functions, and that the compiler has "forgotten" that id is pure and terminating. To make your code compile, you should tell the compiler that id is of type int -<> int (is pure and terminating) by writing : fn id (x : int) :<> int = x (note the change of fun to fn, which means that the function is not recursive. Without this change, the compiler would complain that the function isn’t proved to be terminating) And I agree with you, the error message is strange, the types do mismatch. If I am not mistaken, Guillaume Brunerie 2010/2/2 Matthias Berndt <mat...@gm...> > Hi, > > I've been trying to compile the following code: > > fun id(x:int):int = x:int > val bar:(int) -<fun> int = id > > However i get this strange error message: > > /home/matthias/ATS/atshome/bin/atsopt --output test_dats.c --dynamic > test.dats > /home/matthias/ATS/test.dats: 31(line=2, offs=5) -- 51(line=2, offs=25): > error(3): mismatch of static terms (tyleq): > The needed term is: S2Efun(fun; 0; 0; S2Ecst(int); S2Ecst(int)) > The actual term is: S2Efun(fun; 0; 0; S2Ecst(int); S2Ecst(int)) > exit(ATS): uncaught exception: > ATS_2d0_2e1_2e7_2src_2ats_error_2esats__FatalErrorException(1002) > exit(ATS): [ccomp_file_to_file(test.dats, test_dats.c)] failed. > > The types obviously match, so why does it complain? I'm using anairiats > 0.1.7 > > Also, i'd like to know what the difference between ->, -<> and -<fun> is. > If I > change -<fun> to -> in the above code, anairiats doesn't complain. It gives > the > same message if i use -<>. > > > ------------------------------------------------------------------------------ > The Planet: dedicated and managed hosting, cloud storage, colocation > Stay online with enterprise data centers and the best network in the > business > Choose flexible plans and management services without long-term contracts > Personal 24x7 support from experience hosting pros just a phone call away. > http://p.sf.net/sfu/theplanet-com > _______________________________________________ > ats-lang-users mailing list > ats...@li... > https://lists.sourceforge.net/lists/listinfo/ats-lang-users > |