From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Maxime Devos Newsgroups: gmane.lisp.guile.user Subject: Re: Idiomatic Guile for semigroup/monoid/group? Date: Sun, 02 Jan 2022 10:46:43 +0000 Message-ID: <7af1fd7e8bf7b0c84cdda3a431412bac31b45f18.camel@telenet.be> References: Mime-Version: 1.0 Content-Type: multipart/signed; micalg="pgp-sha512"; protocol="application/pgp-signature"; boundary="=-27GGwtzxN6wxH9V2rgLm" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2137"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Evolution 3.38.3-1 To: Stuart Hungerford , guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sun Jan 02 11:48:03 2022 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n3yPD-0000NP-L8 for guile-user@m.gmane-mx.org; Sun, 02 Jan 2022 11:48:03 +0100 Original-Received: from localhost ([::1]:56172 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n3yP9-0003oU-FY for guile-user@m.gmane-mx.org; Sun, 02 Jan 2022 05:47:59 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:33076) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n3yO6-0003HZ-Ft for guile-user@gnu.org; Sun, 02 Jan 2022 05:46:54 -0500 Original-Received: from [2a02:1800:110:4::f00:19] (port=57800 helo=laurent.telenet-ops.be) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n3yO4-00062r-1I for guile-user@gnu.org; Sun, 02 Jan 2022 05:46:54 -0500 Original-Received: from ptr-bvsjgyhxw7psv60dyze.18120a2.ip6.access.telenet.be ([IPv6:2a02:1811:8c09:9d00:3c5f:2eff:feb0:ba5a]) by laurent.telenet-ops.be with bizsmtp id dmmo2600L4UW6Th01mmoa3; Sun, 02 Jan 2022 11:46:48 +0100 In-Reply-To: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telenet.be; s=r21; t=1641120408; bh=O8wsIkoqkICOhcejxgM1bYHiThGvRyoBjzyXt5e4Y/4=; h=Subject:From:To:Date:In-Reply-To:References; b=o6q4QfZPqscVmlrQeTn3Fu8HujE5jBJ71Okv6ZH8Sf66PmCIeGVYDoEAuaSBj5CLZ GnFTe+Jo5lgIF8pMleZxnSxJvhCeO7j/9QDqEW2Kny5j1QT/QKtBHNUgovZxOBqNF0 66F/qYsbk0px8vwFH+HmMhxbFKS4XYfOoX+ksWF5V8gGxRK6EPKeceienjomnVrT1x fLTeRFXA0uwsGpF+EiF6wpXA8Axil4NpC3kOT5BmxhR7wGIrYAD85KcJnxlh6Pb8Si BNr2hNIVErUWhGfl5olqKCzDaS7NB4dVuY3L/8TIvv+FOBcxqgwFpQIv2x8VZU0LuK pn0i3+KNVFx1A== X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a02:1800:110:4::f00:19 (failed) Received-SPF: pass client-ip=2a02:1800:110:4::f00:19; envelope-from=maximedevos@telenet.be; helo=laurent.telenet-ops.be X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:17944 Archived-At: --=-27GGwtzxN6wxH9V2rgLm Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Stuart Hungerford schreef op zo 02-01-2022 om 10:45 [+1100]: > In Haskell/Idris/Purescript/Swift/Rust I'd be looking to > typeclasses/protocols or traits to model a semigroup, monoid or group. > In OOP languages I'd be looking to some kind of abstract base class to > model each structure. >=20 > What would the idiomatic Guile forms be to work with these structures? > Would it involve GOOPS or records? I wouldn't recommend using GOOPS methods, because a carrier set can have many groups. E.g., on the rational numbers ( in GOOPS), both the multiplication group and the addition group can be defined, but they aren't isomorphic. (I'm ignoring 0 here) My suggestion is to do as Haskell does, but make type class instances explicit. E.g., in Haskell one could define exponentiation (multiplicative) / repeated addition (additive, not sure about standard terminology) as something like -- Not sure about the exact syntax, it has been a while! exp :: Group G =3D> Integer -> G -> G exp 0 _ =3D identity exp (+ 1 n) g =3D g * exp n g This can be made more explicit: -- first argument: identity element -- second argument: function inverting an element -- third argument: multiplication data Group G =3D Group G (G -> G) (G -> G -> G) identity :: Group G -> G identity =3D _ -- maybe shorten to 'id' mult :: Group G -> G -> G -> G -- maybe shorten to '*' in Scheme mult =3D _ inverse :: Group G -> G -> G -- maybe shorten to '=E2=81=BB=C2=B9' in Schem= e exp :: Group G -> Integer -> G -> G exp gr 0 _ =3D identity gr exp gr (+ 1 n) g =3D mult gr g (exp gr n g) The downside is that passing all these 'Group G' objects around might be a bit tedious. Anyway, possibly things like this are already implemented in Theme-D (not sure though): looking at the properties of Theme-D listed at : * [...] * Static type system * An object system * A module system * *Statically* and dynamically dispatched multimethods (emphasis mine) * Parametrized (type parameters) classes, types, and procedures * [...] * Numeric tower * [...] Greetings, Maxime. --=-27GGwtzxN6wxH9V2rgLm Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iI0EABYKADUWIQTB8z7iDFKP233XAR9J4+4iGRcl7gUCYdGCkxccbWF4aW1lZGV2 b3NAdGVsZW5ldC5iZQAKCRBJ4+4iGRcl7obbAQCS7RlXs91JqYwPbeoa0tb5YJMc Y4a755OerCYY5l/E7gD/bhCC9p8HFywSyqUkYXJ5OjmKDshNM+6/GZuwHRNgMQk= =c2s6 -----END PGP SIGNATURE----- --=-27GGwtzxN6wxH9V2rgLm--