[curry] Choosing default instances in Curry

From: Andy Jost <Andrew.Jost_at_synopsys.com>
Date: Fri, 17 May 2019 18:21:50 +0000

I'm trying to understand the implementation of typeclasses in Curry so that=
 I can implement them in my compiler. Is there some documentation describi=
ng how dictionaries are implemented, including the naming conventions used?

One problem I face is knowing how to choose default instances. For example=
, the program "main = 1 + 1" translates to the following FlatCurry:

program "test"
  import "Prelude"
  function "test.main" 1
    lhs_vars [1]
    Node "Prelude.apply" (
      Node "Prelude.apply" (
        Node "Prelude.+" (
          var 1 ) ,
        Node "Prelude.apply" (
          Node "Prelude.fromInt" (
            var 1 ) ,
          int 1 ) ) ,
      Node "Prelude.apply" (
        Node "Prelude.fromInt" (
          var 1 ) ,
        int 1 ) )

Function "main" expects an implicit argument that is an instance of Prelude=
.Num. This is because no type declaration was specified, so its type is "N=
um a => a". If I were to declare main as having a concrete type such as =
Int or Float, then it would take no arguments.

KiCS2 and PAKCS can run this program, so they must somehow choose a default=
 instance. How is this done?

I'm especially bothered that the FlatCurry appears to be missing crucial in=
formation - i.e., the fact that "main" expects a Num instance is not mentio=
ned in the FlatCurry. How do other Curry implementations know to pass a Nu=
m dictionary and how is the default instance chosen?

-Andy



_______________________________________________
curry mailing list -- curry_at_lists.rwth-aachen.de
To unsubscribe send an email to curry-leave_at_lists.rwth-aachen.de
https://lists.rwth-aachen.de/postorius/lists/curry.lists.rwth-aachen.de
Received on Mo Mai 20 2019 - 18:28:29 CEST

This archive was generated by hypermail 2.3.0 : Do Feb 01 2024 - 07:15:13 CET