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

Generalize types of polymorphic functions #9

Open
emilaxelsson opened this issue Oct 19, 2012 · 2 comments
Open

Generalize types of polymorphic functions #9

emilaxelsson opened this issue Oct 19, 2012 · 2 comments

Comments

@emilaxelsson
Copy link
Member

For example:

getIx :: Syntax a => Data [Internal a] -> Data Index -> a
setIx :: Syntax a => Data [Internal a] -> Data Index -> a -> Data [Internal a]

Is this a good idea?

@emwap
Copy link
Member

emwap commented Oct 22, 2012

That would make the following valid:

{-# LANGUAGE FlexibleContexts #-}

import Feldspar
import Feldspar.Vector

ex1 :: Syntax a => Data [Internal (Vector a)] -> Data Index -> Vector a
ex1 = getIx

ex2 :: Syntax (M a) => Data [Internal (M a)] -> Data Index -> M a
ex2 = getIx

While 'ex1' might be useful, I'm not sure we want to allow 'ex2'.
Do you have a use case?

@emilaxelsson
Copy link
Member Author

No M a doesn't have a Syntax instance so ex2 would not be allowed.

I'm just assuming it might be useful to do things like setIx a i (1,2). Of course it's not much more typing to say setIx a i (resugar (1,2)), but it seems quite natural to make such functions as general as possible. The idea would be to generalize all polymorphic types Data a in the core language (but not e.g. Data [a] or Data Bool). The downside is that for functions like getIx, we lose some type inference (since a cannot be inferred from Internal a).

Currently, e.g. condition and forLoop are generalized to Syntax types, but their types don't mention Internal, so no type inference is lost.

Now that I think about it, the loss of type inference seems to kill this proposal. Maybe the rule-of-thumb should be to keep the core language interface free from type functions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants