Skip to content

Conversation

@garyb
Copy link
Member

@garyb garyb commented Oct 10, 2016

Resolves #37, resolves #41

@garyb
Copy link
Member Author

garyb commented Oct 10, 2016

Figured I may as well add the general ForeignError from #37 - it seems harmless enough.

@paf31
Copy link
Contributor

paf31 commented Oct 10, 2016

Looks good, but let's discuss the use of NonEmpty. I think it would be nice to move NonEmpty to the top level, make it a Semigroup and give an Alt instance to F which combined errors using that Semigroup. What do you think?

@garyb
Copy link
Member Author

garyb commented Oct 10, 2016

I did start looking at that, but it wasn't really obvious to me how you'd actually get more than one failure out of the "parsing" anyway?

@paf31
Copy link
Contributor

paf31 commented Oct 10, 2016

Using <|>?

@paf31
Copy link
Contributor

paf31 commented Oct 10, 2016

i.e. using the Except (NonEmpty ForeignError) monad in place of Either.

@garyb
Copy link
Member Author

garyb commented Oct 10, 2016

Ok, sounds good to me. I take it we don't need the list in TypeError then? (although it will give slightly less good error messages)

@paf31
Copy link
Contributor

paf31 commented Oct 10, 2016

I think we could get rid of that, since that's more of an error message rendering problem, right?

@garyb
Copy link
Member Author

garyb commented Oct 10, 2016

Yeah, exactly

keys value
| isNull value = Left $ TypeMismatch (NE.singleton "object") "null"
| isUndefined value = Left $ TypeMismatch (NE.singleton "object") "undefined"
| isNull value = Left $ NE.singleton $ TypeMismatch "object" "null"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth extracting Left <<< NE.singleton <<< TypeMismatch into a function here.

-- | An error monad, used in this library to encode possible failures when
-- | dealing with foreign data.
type F = Either ForeignError
type F = Either (NE.NonEmpty List ForeignError)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this use Except so that we get the right Alt instance?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right, I was trying to avoid adding the -transformers dependency, but yep, good point.

@paf31
Copy link
Contributor

paf31 commented Oct 11, 2016

👍 Thanks for this.

@garyb
Copy link
Member Author

garyb commented Oct 11, 2016

Maybe the MultipleErrors I just added here would be something worth adding in transformers?

@paf31
Copy link
Contributor

paf31 commented Oct 11, 2016

Could we add it in nonempty? We have non-empty containers, but we could also have non-empty base types with Monoid a => Semigroup (NonEmpty a).

@garyb
Copy link
Member Author

garyb commented Oct 11, 2016

Something like newtype NonEmptySemigroup s a = Semigroup s => NonEmptySemigroup (NonEmpty f a)? (but not with the constraint there obviously), or like newtype NonEmptyList = NonEmptyList (NonEmpty List)? We can't do the latter due to the dependency order, but something like the former would work.

@paf31
Copy link
Contributor

paf31 commented Oct 11, 2016

Never mind, I'm not sure what I was thinking. I think having a newtype around NonEmpty List somewhere would be good, although I'm fine with leaving this here too.

@garyb
Copy link
Member Author

garyb commented Oct 11, 2016

Yeah, it's fine here, just it seems like something that I'll want to use commonly with Except / MonadError in cases that have nothing to do with Foreign.

@garyb
Copy link
Member Author

garyb commented Oct 11, 2016

I could just make a new library for it I guess.

@paf31
Copy link
Contributor

paf31 commented Oct 12, 2016

Could it go into lists?

@garyb
Copy link
Member Author

garyb commented Oct 12, 2016

Yeah, I'll do that.

@paf31
Copy link
Contributor

paf31 commented Oct 12, 2016

What about leaving the type here for now, hiding its constructor and adding non-empty lists into lists later?

@garyb
Copy link
Member Author

garyb commented Oct 13, 2016

Done at last I think!

@paf31
Copy link
Contributor

paf31 commented Oct 13, 2016

👍 Thanks, looks great!

@garyb garyb merged commit b73e22f into master Oct 13, 2016
@garyb garyb deleted the bump branch October 13, 2016 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API question about ForeignError

4 participants