From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id EJj8AIIkDGLLGQEAgWs5BA (envelope-from ) for ; Tue, 15 Feb 2022 23:09:06 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id APhjNYEkDGIQ3gAAG6o9tA (envelope-from ) for ; Tue, 15 Feb 2022 23:09:05 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 76FB6D4B1 for ; Tue, 15 Feb 2022 23:09:05 +0100 (CET) Received: from localhost ([::1]:36406 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nK60O-0002zN-1y for larch@yhetil.org; Tue, 15 Feb 2022 17:09:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40888) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nK5dM-0006xc-Qk for guix-devel@gnu.org; Tue, 15 Feb 2022 16:45:16 -0500 Received: from [2607:f8b0:4864:20::72c] (port=41839 helo=mail-qk1-x72c.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nK5dK-00034Y-TO for guix-devel@gnu.org; Tue, 15 Feb 2022 16:45:16 -0500 Received: by mail-qk1-x72c.google.com with SMTP id d84so31469qke.8 for ; Tue, 15 Feb 2022 13:45:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philipmcgrath.com; s=google; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to:content-transfer-encoding; bh=hupTkCae8r3JJW+TG8Mo/AGzU1+t0V5eCRHMzu9jhhM=; b=AQS9bO7n7q+vMMW4+Jl4AXM37B9GbS2XMO6HZSHW0dCCdDsrXreFXIMcYKlsJd/EYM yZJPiugolWW+yUFo88mMEjqX2b1Ze9Qu3EqVLjj0EPkVvBvLUNtaYdx5QTGlRyX4WWGg 9znulxqdGEPHfHp+4g0wnN8qPe6NOYUIuyVJ7O2Hr1jDHR6IArbUQzegxxZETgaS0VRm 6PvHl5t6Km8dDin5NF6T8w5vr6RopKHMzBQK2nHjvv7fkWHOMyyxADyw5Cs41/XkKcVN UqT5//EYk9sIygXcGr9QsbwlayAPvk/cXf8ZKmpZUoCI2yl5HW14SaM8Xt1Hnuu5UsrI LpJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=hupTkCae8r3JJW+TG8Mo/AGzU1+t0V5eCRHMzu9jhhM=; b=4HJzvi1+3cn1Znz9AkpVoyOTlOeBEIE+ivzdYEVuczwMfecTwdgjWN8M25DVs6b3h8 ZHpPGZBNIGwbn0UEF9Fwof5ZAa5zf3wnt8HmM38/vTbOgbo6z6bdlsmCmWoYO28QhHpA 7Z4bo9aEugraLzklbeS66dVvmlT3K9IWsz6yWpHjxj2AdSl85TDCB2bqvknpbHaQG7gl Ui/3whp7QincqvvQRSx1nDROx+FYQBVgHvliXYNJBs1W9dtZ5EqztBV26G/NvFHQZbAW 2H7br3zsJitmeiSuC4NVpVQ/Jhvrg3NAuIaC5N0kqS7HVAfk3E3IEcA5wzpv5vXGzCdG prNg== X-Gm-Message-State: AOAM533aMeMsEjr6/x38NTmcLi9ntf25EJrM2Kv3vf4ESFlSPyrr3wbR 81lcZJZaakw65YdMFGoJL9PvdQ== X-Google-Smtp-Source: ABdhPJx1f7O+6hIS7sE1DNLVIXlS/Y/IsL7YtppGz5YQJA9caDnl1oP47Z234F4Wm4/X8FCl6ky4aA== X-Received: by 2002:ae9:eb89:: with SMTP id b131mr596332qkg.509.1644961513048; Tue, 15 Feb 2022 13:45:13 -0800 (PST) Received: from [192.168.45.36] (c-73-125-98-51.hsd1.fl.comcast.net. [73.125.98.51]) by smtp.gmail.com with ESMTPSA id v12sm18055165qkl.74.2022.02.15.13.45.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Feb 2022 13:45:12 -0800 (PST) Message-ID: Date: Tue, 15 Feb 2022 16:45:11 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: better error messages through assertions Content-Language: en-US To: Ricardo Wurmus , guix-devel@gnu.org, Maxime Devos References: <87ilthoxvu.fsf@elephly.net> From: Philip McGrath In-Reply-To: <87ilthoxvu.fsf@elephly.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::72c (failed) Received-SPF: neutral client-ip=2607:f8b0:4864:20::72c; envelope-from=philip@philipmcgrath.com; helo=mail-qk1-x72c.google.com X-Spam_score_int: 4 X-Spam_score: 0.4 X-Spam_bar: / X-Spam_report: (0.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-0.001, PDS_HP_HELO_NORDNS=0.904, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: guix-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+larch=yhetil.org@gnu.org Sender: "Guix-devel" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1644962945; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=hupTkCae8r3JJW+TG8Mo/AGzU1+t0V5eCRHMzu9jhhM=; b=Mb9gUX4XUm/M8UWD681kdKd7Z03H+1RbxqcfLubbdXvXHO+kbP1/KFqaJ49Frs8ONdQwJ5 Rr357TbKtdjc/UtAwGEw9s8usEfEcRiRzpe2vvjL+XeI45MQjm0KHilI7B+oI4e5vESj5H f8lKRLXXFR0jmbcocqggeZQqCgVC8T3dsGB1Hn5BonBP3YUcixb38CMZwcs6Hc6Hs+y5Us L/Typfx4Dy3ke9FpA0xSsdOKm7prZysNwqXgRF2n8/6pcuH5wUQsAQgg7aqfTZSMBFrYiM 2B7CnyhEDoBbIux8/rkJh5uE+oldlGAzIiB39WtUCiuYfkiWoYl0fSwczv9ULQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1644962945; a=rsa-sha256; cv=none; b=l9WL5eS9Eig4eB9IWshnKe4F6rqkNIneD7ud+HvTHPMaxHPs6emwPGtqXRSgJChgCVedZx w6ZnZr/ayDv2oHKyaWHkttIe3iOZv78H5oQNrfw3CesyitIB3m758nxglXZTp3CTnXXqLw FnuAB/+YHI7RZFqWUd9GRsfWspI3w3pn6pAyzIHNtEUfPuDnAm1Zhk9w7S43c+xfRhz4bD Untdm9N7uAIXoXHlcHdEpPsIvINlSE6tdrfKRwH8/8cYzY9iUYhlY22FGn8sJz5lX0LYBE 96iDseqBiieVRI2Zovw8uYqgBxtVFdmluKBNeMSHEqjBt5kpVaGWtHCVfqUUDg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=philipmcgrath.com header.s=google header.b=AQS9bO7n; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-devel-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -9.13 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=philipmcgrath.com header.s=google header.b=AQS9bO7n; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-devel-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 76FB6D4B1 X-Spam-Score: -9.13 X-Migadu-Scanner: scn0.migadu.com X-TUID: t4QsJueyKP9T Hi, On 2/14/22 17:32, Ricardo Wurmus wrote: > As you can probably tell easily by looking at this message, the > “service” field of the operating system configuration looked something > like this: > > (services (append (list a b c %desktop-services) #;oops)) > > instead of this > > (services (append (list a b c) %desktop-services)) > > This is because INSTANTIATE-MISSING-SERVICES — and FOLD-SERVICES, and > many more — assumes that it is only passed a plain list of services. It > then proceeds to call SERVICE-KIND on what may or may not be a service. > > I think we should add simple type checks, something like this: > > (define (listof pred) > (lambda (thing) > (and (list? thing) (every pred thing)))) > … > (define (assert-type type-check thing message) > (or (false-if-exception (type-check thing)) > (report-error (G_ "type error: …\n" message)))) > > ;; Use ASSERT-TYPE in an example procedure. > (define (do-something-with-services services) > (assert-type (listof service?) services > "SERVICES must be a list of values.") > > ;; Do things… > (map service-kind services)) > > What do you think? There are many different ways of implementing this > (a new variant of DEFINE that also accepts a type declaration, an assert > like above, a fancier assert that composes a helpful error message by > itself, a separate type declaration that is looked up only when the > corresponding procedure is called in a certain context, etc), but I’d > first like to know if there is consensus that we want something like > this. > As a Guix user and contributor, I would love better error messages. As a Racketeer, I think you're half way to reinventing contracts. In particular, since the operating system services field is thunked, this example already points to the desirability of higher-order contracts. Using "contracts" need not initially involve all the bells and whistles of Racket's contract library. For example, higher-order contracts can be implemented with `lambda` in the absence of special runtime support for chaperones and impersonators, as illustrated in [1]. But the Racket community has accumulated a great deal of both theoretical insight and implementation experience in many subtle corners of this problem: I hope Guix can build on that experience. -Philip [1]: https://docs.racket-lang.org/guide/Building_New_Contracts.html