0

In Prelude, unlines work as expected. Below is the example

GHCi>unlines ["aa","bb","bb"] "aa\nbb\nbb\n" 

But why does lines not work. Even the type signature says that it can only take numbers.

GHCi>:t lines lines :: Num t => [t] 

So, if I try

GHCi>lines "aa\nbb\nbb\n" 

why do I get an error? Is there a lines that I need to import?

Regards,

5
  • What does GHCi>:i lines give you? That should show where the lines you're seeing is defined. Commented Mar 7, 2017 at 14:42
  • 1
    In GHCi it says lines :: String -> [String]. So you have imported a different `lines. Commented Mar 7, 2017 at 14:44
  • Yes mine shows GHCi>:i lines lines :: Num t => [t] -- Defined at <interactive>:14:1. Can you please tell me how I can get the correct one? Commented Mar 7, 2017 at 14:49
  • Thanks I fixed it, i just restarted it and it works fine. Commented Mar 7, 2017 at 14:52
  • 1
    When GHCi says "Defined at <interactive>:14:1", it means that lines was re-defined in GHCi (input line 14). Hence, you are not using the standard lines. Commented Mar 7, 2017 at 15:55

1 Answer 1

5

Are you sure that you are not shadowing the lines function:

:t lines lines :: String -> [String] 

Make sure you have not define a lines variable. As @ChadGilbert mention you can use :i

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.