Why do some function calls fail to work without a type application?

Vanson Samuel

I am having trouble understanding how type applications work. Why can sing in refuteRefuteKnockable be used without a type application when the call to sing in knockableOrOpened will fail to type check without a type application?

 refuteRefuteKnockable :: SingI s => Refuted (Refuted (Knockable s)) -> Knockable s
 refuteRefuteKnockable rrK =
   case isKnockable $ sing of
     Proved k -> k
     Disproved rK -> absurd $ rrK rK

 knockableOrOpened :: forall s. SingI s => Or Knockable ((:~:) Opened) s
 knockableOrOpened =
   case sing @s of
     SOpened -> OrRight $ Refl
     SClosed -> OrLeft KnockClosed
     SLocked -> OrLeft KnockLocked

I am working from the following codebase: https://github.com/mstksg/inCode/blob/master/code-samples/singletons/Door3.hs

chi

Type inference is the cause. This type contains s ...

refuteRefuteKnockable :: SingI s => Refuted (Refuted (Knockable s)) -> Knockable s
                                                                       ^^^^^^^^^^^

So, this

 refuteRefuteKnockable rrK =
   case isKnockable $ sing of
     Proved k -> k
                ^^^

must have type Knockable s. Hence, the type of Proved k is inferred, probably containing s as well. That is the same type of isKnockable $ sing, from which we infer what type should be applied to sing (exploiting the signature of isKnockable). GHC does all of this for us.

In the latter example, we can't perform the same reasoning.

case sing of
     SOpened -> OrRight $ Refl
     SClosed -> OrLeft KnockClosed
     SLocked -> OrLeft KnockLocked

is ambiguous because, even if the three branches must return a known type, we can still call sing on a different type then s and make everything typecheck. Since there isn't a unique s, inference can not work.

Note that above I had to guess a few things. If you shared the definitions of your types, we could be more accurate. (I.e., where is SOpened defined? What about Knockable, etc.?)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why it's possible to address some variables without quotes in function calls?

From Dev

'setTimeOut' calls in JavaScript 'for' loops, why do they fail?

From Dev

Why do most of my installers fail to work?

From Dev

Why do nth-of-type elements fail to work at third-element?

From Dev

Haskell - How the construct do calls fail function from Monad?

From Dev

Why does event.preventDefault() work without passing event as an argument in a callback function in some cases in jQuery?

From Dev

Why my code works without chroot function, but fail with chroot function?

From Dev

dplyr: Why do some operations work "rowwise" without calling rowwise() and others dont?

From Java

Why do some Linux system calls not have a wrapper, but are documented as if they do?

From Javascript

What happens with $q.all() when some calls work and others fail?

From Dev

Why do some statements fail to execute when run in a thread?

From Dev

Why does 2.11.1 fail with error: not found: type Application?

From Dev

Why do some actions not work with Remote Desktop?

From Dev

Why do only some events work with pygame?

From Javascript

Why do I not get type errors in my Node Application although I specify the type of the function argument?

From Java

Why do some Linux system calls have two man pages?

From Java

Some api calls fail on Android 9

From Dev

Why do cv-qualifiers get removed from function return type in some cases?

From Dev

Why do options in a quoted variable fail, but work when unquoted?

From Dev

Why does Java type inference fail to distinguish between Function and Consumer?

From Dev

Why does this function work with min, but not without?

From Dev

function without argument doesnt work. but why?

From Dev

Why does the function not work without the "if" statement?

From Dev

Why do some js files begin with (function() {

From Dev

Erlang function calls - Why does it not work to call self() as a direct argument?

From Java

Why does * work differently in assignment statements versus function calls?

From Dev

In Python, why do function parameters maintain their value beetween function calls

From Dev

Why would this function fail?

From Dev

Why do aggregation functions work without Group By?

Related Related

  1. 1

    Why it's possible to address some variables without quotes in function calls?

  2. 2

    'setTimeOut' calls in JavaScript 'for' loops, why do they fail?

  3. 3

    Why do most of my installers fail to work?

  4. 4

    Why do nth-of-type elements fail to work at third-element?

  5. 5

    Haskell - How the construct do calls fail function from Monad?

  6. 6

    Why does event.preventDefault() work without passing event as an argument in a callback function in some cases in jQuery?

  7. 7

    Why my code works without chroot function, but fail with chroot function?

  8. 8

    dplyr: Why do some operations work "rowwise" without calling rowwise() and others dont?

  9. 9

    Why do some Linux system calls not have a wrapper, but are documented as if they do?

  10. 10

    What happens with $q.all() when some calls work and others fail?

  11. 11

    Why do some statements fail to execute when run in a thread?

  12. 12

    Why does 2.11.1 fail with error: not found: type Application?

  13. 13

    Why do some actions not work with Remote Desktop?

  14. 14

    Why do only some events work with pygame?

  15. 15

    Why do I not get type errors in my Node Application although I specify the type of the function argument?

  16. 16

    Why do some Linux system calls have two man pages?

  17. 17

    Some api calls fail on Android 9

  18. 18

    Why do cv-qualifiers get removed from function return type in some cases?

  19. 19

    Why do options in a quoted variable fail, but work when unquoted?

  20. 20

    Why does Java type inference fail to distinguish between Function and Consumer?

  21. 21

    Why does this function work with min, but not without?

  22. 22

    function without argument doesnt work. but why?

  23. 23

    Why does the function not work without the "if" statement?

  24. 24

    Why do some js files begin with (function() {

  25. 25

    Erlang function calls - Why does it not work to call self() as a direct argument?

  26. 26

    Why does * work differently in assignment statements versus function calls?

  27. 27

    In Python, why do function parameters maintain their value beetween function calls

  28. 28

    Why would this function fail?

  29. 29

    Why do aggregation functions work without Group By?

HotTag

Archive