Should removeDuplicates from Chapter 3 have arguments for Addressentries when called

This is the code I have now

removeDuplicates :: AddressBook -> AddressBook
removeDuplicates = nubBy filterEntry
  where
  filterEntry :: Entry -> Entry -> Boolean
  filterEntry e1 e2 = e1.firstName == e2.firstName
    && e1.lastName == e2.lastName

But I now get an error in the Testing Module

$ spago test
Compiling Data.AddressBook
Compiling Test.Main
Compiling Test.NoPeeking.Solutions
Error found:
in module Test.Main
at test/Main.purs:79:11 - 79:27 (line 79, column 11 - line 79, column 27)

  Unknown value removeDuplicates


See https://github.com/purescript/documentation/blob/master/errors/UnknownName.md for more information,
or to contribute content related to this error.


[error] Failed to build.

By reading the test/Main.purs file, I guess the function is syntactically correct but it doesn’t function as intended

Could you upload the current state of your repo to github and post a link for us to investigate?

I just did. It’s here https://github.com/nospace-here/purescript-book

The problem is you wrote your homework into src/Data/AddressBook.purs instead of the correct place where the book instructs you to: test/MySolutions.purs.

So test/Main.purs doesn’t import your function at all that’s why it doesn’t know about it.

@milesfrain I guess it’s pretty easy to forget from chapter to chapter that the correct place to solve exercises is Test.MySolutions as this instruction is given in chapter 2.

But my inputs in src/Data/AddressBook.purs do directly influence the output of spago test like all the previous exercies within the chapter

Well listen, I didn’t take a super deep look at it, maybe you rewrote some functions with your own implementation or something like that, so obviously that would influence the test.

But just read that entry in chapter 2 I linked to from the book and hopefully you’ll progress smother if you stick with the instructions.

If you look at your test/Main.purs file you’ll see that it imports some specific things from Data.AddressBook (your removeDuplicates function isn’t among them):

import Data.AddressBook (AddressBook, Entry, emptyBook, findEntry, insertEntry, findEntryByStreet, isInBook)

On the other hand it imports everything from Test.MySolutions:

import Test.MySolutions

So just move your homework there and maybe you’ll get some other errors :slight_smile:

I now put my exercise solutions to Test.MySolutions as you said but now it gives me a different error

$ spago test
Compiling Test.MySolutions
Compiling Data.AddressBook
Compiling Test.NoPeeking.Solutions
Error 1 of 3:

  in module Test.MySolutions
  at test/MySolutions.purs:7:32 - 7:43 (line 7, column 32 - line 7, column 43)

    Unknown type AddressBook


  See https://github.com/purescript/documentation/blob/master/errors/UnknownName.md for more information,
  or to contribute content related to this error.

Error 2 of 3:

  in module Test.MySolutions
  at test/MySolutions.purs:13:33 - 13:44 (line 13, column 33 - line 13, column 44)

    Unknown type AddressBook


  See https://github.com/purescript/documentation/blob/master/errors/UnknownName.md for more information,
  or to contribute content related to this error.

Error 3 of 3:

  in module Test.MySolutions
  at test/MySolutions.purs:19:21 - 19:32 (line 19, column 21 - line 19, column 32)

    Unknown type AddressBook


  See https://github.com/purescript/documentation/blob/master/errors/UnknownName.md for more information,
  or to contribute content related to this error.


[error] Failed to build.

Alright so, maybe you won’t like to hear this, but I think you should start over from the Chapter 1 and read slowly. Because most of these things can be solved quite easily by you if you just pay a bit more attention.

Chapter 2 has exercises with hints that explains all about import and how to use modules. It seems to me that you just skipped ahead without digesting and trying out the initial exercises, or you just skimmed through them without understanding what you’re doing.

Imports can be easily forgotten. I highly recommend you use a text editor and set it up to work with purescript-language-server as it gives you autocompletion and some other nice stuff, and I’d say with PureScript it’s pretty much indispensable, cause no one is going to precisely remember where functions and values come from what modules.

I also highly recommend you go through Haskell Wikibook as most of the info applies to PureScript too and you can just transfer the knowledge in 90% of the cases.

If you have Haskell and can experiment with both even better. The PureScript book, although pretty beginner-level, it isn’t exactly for people that have no idea about the syntax. That’s where the Haskell Wikibook can complete the knowledge, cause the syntax is 90% similar, apart from some advanced concepts.

Good luck!

2 Likes

It may probably have probably forgotten of th eariler chapters as it was a while ago that I fully read it. But thanks for the hints and the other resources to this language. Will look into it

Moving the removeDuplicates function to Test.Mysolutions made the test work fine now. Thank you everyone

1 Like