Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does signature change after an assignment

Tags:

haskell

ghci

Playing around in ghci I got the following expression: unlines . map (\(a,b) -> show a ++ " " ++ show b)

Now when I check it via :t I get:

> :t  unlines . map (\(a,b) -> show a ++ " " ++ show b)
unlines . map (\(a,b) -> show a ++ " " ++ show b)
  :: (Show a, Show a1) => [(a, a1)] -> String

So exactly as expected. But now if I try to assign it to some name, I get a more specific signature than the original one:

> let f = unlines . map (\(a,b) -> show a ++ " " ++ show b)
> :t f
f :: [((), ())] -> String

Why does this happen?

like image 855
viraptor Avatar asked Mar 16 '13 16:03

viraptor


People also ask

Does it matter what signature you use?

Does your signature really have to be your actual name, or can it be something else entirely? If you need a legal opinion, you should consult an attorney, but, generally speaking, your signature can be whatever you want it to be.

Does your signature need to be the same?

Your signature should not be exactly the same each time you write. That is a sign of forgery. But it should appear very similar, with certain key characteristics, such as letters you loop and letters you don't — and it should be unique — not like anybody else's signature.

Why does a signature matter?

A legally binding signature makes an agreement official once all parties have placed their signatures on a contract. Signatures are the most common method of indicating that you have read over and agreed to the terms, even if a person's signature is so stylized and unique that's illegible.

What is the effect of signature to a written document?

A signature on a contractual document or other written agreement, demonstrates that a party has read, understood and consents to the terms and conditions in a contract. A party to an agreement is bound by his signature, regardless of whether he has actually read the contract or not.


2 Answers

Because of the monomorphism restriction, definitions of the form x = ... (no parameters) are given a monomorphic (i.e. non-polymorphic) type, which usually involves some defaulting as mentioned in the other answer.

To prevent this from happening, either add a type signature to your definition, or disable the monomorphism restriction using :set -XNoMonomorphismRestriction. You can add this to your .ghci file to have it run automatically on startup until it gets disabled by default in GHCi in some future version.

like image 110
hammar Avatar answered Sep 28 '22 08:09

hammar


Defaulting rules.

When you type stuff in GHCi, it attempts to apply default types. IIRC, for things with a Num constraint it picks Integer, for Fractional it picks Double, and for everything else it picks ().

If you write this in a Haskell source file and load it into GHCi, this doesn't happen (I believe).

I think you can also say something like default Int to change the defaulting rules on a per-module basis.

like image 37
MathematicalOrchid Avatar answered Sep 28 '22 08:09

MathematicalOrchid