Skip to content
This repository was archived by the owner on Nov 26, 2020. It is now read-only.

Add some instances#4

Merged
paf31 merged 2 commits into
purescript-deprecated:masterfrom
joneshf:add-some-instances
Jun 3, 2017
Merged

Add some instances#4
paf31 merged 2 commits into
purescript-deprecated:masterfrom
joneshf:add-some-instances

Conversation

@joneshf

@joneshf joneshf commented May 28, 2017

Copy link
Copy Markdown
Contributor

I found myself wanting Functor Proxy. So I added that. Then I figured, what the heck, let's add everything we can.

This does add a dependency on prelude. I'm not sure if that's wanted, or if it's been avoided for a reason.

I'm fine with throwing this all away if it's not wanted.

Comment thread src/Type/Proxy.purs

instance commutativeRingProxy :: CommutativeRing (Proxy a)

instance discardProxy :: Discard (Proxy a) where

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

So this one means we'd allow discarding values of type Proxy a in do notation. Discard is meant for types like Unit so I'm not sure that's what we want.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I mean, of course, it is a unit type, but somehow it seems to convey more information.

That said, we can't use that information in a pattern match, since we can't bind type variables, so actually I'm fine with this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, up to you whether we keep these Discard instances. I don't have enough experience with it to know if it's a good idea or a bad idea.

@paf31

paf31 commented May 28, 2017

Copy link
Copy Markdown

👍 I like it, thanks!

@garyb

garyb commented May 29, 2017

Copy link
Copy Markdown
Member

A question tangentially related to this: what happens about instances with purescript/purescript/pull/2846? They'll just be impossible?

@paf31

paf31 commented May 29, 2017

Copy link
Copy Markdown

@garyb Do you think those instances would be useful? I'll have to think if the polykindedness of the instances would be an issue.

@garyb

garyb commented May 29, 2017

Copy link
Copy Markdown
Member

I don't know, it was just a thought. Maybe this is something that would need real PolyKinds. Here's what happens in GHC:

{-# LANGUAGE KindSignatures, PolyKinds #-}

data Proxy (a :: k) = Proxy

instance Functor Proxy where
  fmap _ _ = Proxy

data Const a b = Const a

bar :: Proxy Int
bar = Proxy

foo :: Proxy Const
foo = Proxy

barB = const True <$> bar

-- Only becomes an error here, everything before this is 👌
fooB = const True <$> foo
test.hs:18:23: error:
    • Couldn't match kind ‘* -> k -> *’ with ‘*’
      When matching the kind of ‘Proxy’
    • In the second argument of ‘(<$>)’, namely ‘foo’
      In the expression: const True <$> foo
      In an equation for ‘fooB’: fooB = const True <$> foo
    • Relevant bindings include
        fooB :: Proxy Bool (bound at test.hs:18:1)

Kind of interesting!

@paf31 paf31 merged commit 19ac791 into purescript-deprecated:master Jun 3, 2017
@paf31

paf31 commented Jun 3, 2017

Copy link
Copy Markdown

Thanks!

@joneshf joneshf deleted the add-some-instances branch June 4, 2017 02:39
@safareli

Copy link
Copy Markdown

Any use case of let's say Bind instance on proxy? or any other instance?

@paf31

paf31 commented Apr 19, 2018

Copy link
Copy Markdown

Proxy is the terminal object in the category of monads, which might be useful. It's sort of useful in a weird way for designing DSLs, when you want to not bother implementing something:

http://hackage.haskell.org/package/acme-all-monad

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants