Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback #1

Closed
paf31 opened this issue Dec 16, 2014 · 7 comments
Closed

Feedback #1

paf31 opened this issue Dec 16, 2014 · 7 comments

Comments

@paf31
Copy link

paf31 commented Dec 16, 2014

Sorry I missed your IRC message.

I like this idea. Here is some feedback:

  • I would move the tests into a tests directory
  • Give context a foreign type, or even use Data.Foreign.Foreign.
  • I would use Eff, since window is mutable.
@Fresheyeball
Copy link
Owner

Interesting. Ok, so I agree on Eff, but I'm not sure what you are looking for with Data.Foreign.Foreign.

@paf31
Copy link
Author

paf31 commented Dec 16, 2014

Well it is unsafe to use the type forall e. { | e} because then I can access any property, even those which don't exist.

forall e. { | e} is an antipattern in my opinion. I don't know where it came from, but a lot of libraries seem to use it to represent "any record". Given parametricity, that type should be uninhabited.

@Fresheyeball
Copy link
Owner

So, yes its unsafe. But doesn't IsForeign require that all the properties be defined upfront? This needs to be extensible. So an extensible record was the tool I reached for.

@paf31
Copy link
Author

paf31 commented Dec 16, 2014

You don't need to use IsForeign if you don't want to. For example:

vendor = context >>= getVendor
  where
  getVendor ctx = do
    nav <- ctx ! "navigator"
    vdr <- nav ! "vendor"
    readString vdr

My point is just that it is unsafe, so I think it should be marked that way, either by name or by type.

@Fresheyeball
Copy link
Owner

I agree with your point. What is the | in your example? What is the type of context in your example? context :: Eff (stuff) Foreign? Its still not clear to me how to make this flexible and safe.

@paf31
Copy link
Author

paf31 commented Dec 16, 2014

! is defined in Data.Foreign.Index.

It really depends how safe you want to me. Another option is to just give it the type forall eff a. Eff (context :: Context | eff) a, but to rename it to something like unsafeContext, to make it clear that the user needs to watch out for the types.

Ideally in that case, the user wouldn't use unsafeContext directly, but would alias it with a stricter type:

window :: Eff ... { navigator :: { vendor :: String } }
window = unsafeContext

A third and better option (in my opinion) is to use a foreign type:

foreign import data Context :: *

The user can then choose to coerce it if they want to.

@Fresheyeball
Copy link
Owner

Ok I had this foreign import data Context :: * because its expressive.

foreign import data Context :: *

But I got rid of it because I couldn't get it to unify for a record type. How would it be coerced?

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

No branches or pull requests

2 participants