dark icon indicating copy to clipboard operation
dark copied to clipboard

Support Tuple User Fn arguments and return types.

Open StachuDotNet opened this issue 2 years ago • 4 comments

As of #4182 we won't be allowing users to use tuples quite yet, so this functionality seems safe for now.

There are a few parts:

  • type checking in the backend (see below comment)
  • add TTuple to allowedParamTypes in Autocomplete.res,
    • this will currently also effect allowedParamTipes
  • testing of type checking (TypeChecker.Tests.fs)
  • some stdlib functions to be used here^

StachuDotNet avatar Jul 05 '22 15:07 StachuDotNet

Draft of TypeChecker.fs work:

  | TTuple (firstType, secondType, otherTypes), DTuple (first, second, theRest) ->
    // TODO: there's definitely a simpler way to gather these errors, but I'm blanking.
    let errors =
      [ (firstType, first); (secondType, second) ] @ List.zip otherTypes theRest
      |> List.filterMap (fun (t, v) ->
        match unify userTypes t v with
        | Ok () -> None
        | Error err -> Some err)
      |> List.collect (fun errs -> errs)

    match errors with
    | [] -> Ok()
    | errors -> Error errors

StachuDotNet avatar Jul 05 '22 15:07 StachuDotNet

Some commentary here around autocomplete: https://github.com/darklang/dark/pull/4182#discussion_r912372275

StachuDotNet avatar Jul 05 '22 15:07 StachuDotNet

Some commentary here around autocomplete: #4182 (comment)

Clicking this link doesn't get me anything (I think due to github folding). Might be worth copying the text or conversation if it's valuable.

pbiggar avatar Jul 05 '22 15:07 pbiggar

Odd. It takes a second to jump to the right place for me, but does.

Copied commentary:

image image

I think this needs code to parse this (and tests!). I think adding tuples to the interestingDvals should find this.

I also get an error in Blazor when calling functions with tuples of 3 or more iterms:

image image

I think we shouldn't support tuple-typed function parameters until we support polymorphic type signatures. With (I think) all the existing types, such as TList, there's an easy conversion from the old value to the new one: Tlist becomes TList TAny. However, in TTuple, we encode the number of type arguments as well as their actual argument. So if someone has a TTuple, and they call it with a tuple with 7 members, how will we know to convert it to TTuple(TAny,TAny,TAny,TAny,TAny,TAny,TAny) instead of TTuple(TAny,TAny).

StachuDotNet avatar Jul 05 '22 15:07 StachuDotNet

Works in daarklang-next (client part not applicable)

pbiggar avatar Mar 09 '23 03:03 pbiggar