It needs a binder?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

It needs a binder?

Alexander Chen
Hi,

binder.hs

i:: Num a => a

prelude>:l binder.hs
typed_checked.hs:1:1: error:
    The type signature for ‘i’ lacks an accompanying binding
  |
1 | i:: Num a=> a   | ^


binder.hs

i:: Num a => a
i = 2

prelude>:l binder.hs
[1 of 1] Compiling Main             
Ok, one module loaded.


Why does it need a binder to make it work?




_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: It needs a binder?

Dániel Arató
Using classic C/C++/Java terms what you're doing in the first version is analogous to _declaring_ a function but not _defining_ it, e.g.

// binding_incorrect.c
int i();
// No definition leads to an error

// binding_correct.c
int i() {
    return 0;
}

The error message says that you have declared the type of i to be Num a => a, but no corresponding definition was found. That's the reason your second version compiles fine

On Tue, 28 Apr 2020 at 21:22, Alexander Chen <[hidden email]> wrote:
Hi,

binder.hs

i:: Num a => a

prelude>:l binder.hs
typed_checked.hs:1:1: error:
    The type signature for ‘i’ lacks an accompanying binding
  |
1 | i:: Num a=> a   | ^


binder.hs

i:: Num a => a
i = 2

prelude>:l binder.hs
[1 of 1] Compiling Main             
Ok, one module loaded.


Why does it need a binder to make it work?



_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners