[m-users.] [Beginner] Fixing a type error in parameter of foldl
Volker Wysk
post at volker-wysk.de
Sat Oct 15 20:32:33 AEDT 2022
Am Samstag, dem 15.10.2022 um 20:15 +1100 schrieb Zoltan Somogyi:
>
> On Sat, 15 Oct 2022 14:14:07 +0530, Razetime <rraghu.11502 at gmail.com> wrote:
> > This is my program (spoilers for advent of code 2016 day 2):
> >
> > :- module a02.
> >
> > :- interface.
> > :- import_module io.
> > :- pred main(io::di,io::uo) is det.
> > :- type dir ---> u;d;l;r.
> >
> > :- implementation.
> > :- import_module int,string,list,require.
> >
> > :- pred p1(list(dir)::in,int::in,int::out) is det.
> > p1(D,S,F):-foldl(turn,D,S,F).
> >
> > ...
> >
> > however, the types of this predicate 'turn' do not coincide with the
> > types for foldl and I do not understand why. I do not understand why
> > the character type is expected in the first slot.
>
> It is one possible expectation, because you have not told the compiler
> *which* foldl predicate you want to invoke. You have imported two
> modules that both define a predicate named foldl, list and string.
> The first expected type is the type of list.foldl, the second expected type
> is the type of string.foldl, which executes an operation on each *character*
> of its input string. If you replace just "foldl" with "list.foldl" above,
> you get just one expected type.
It compiles when you interchange the first two arguments of "turn".
Volker
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.mercurylang.org/archives/users/attachments/20221015/efd1bf18/attachment.sig>
More information about the users
mailing list