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

Get rid of Proxy# #27

Closed
int-index opened this issue Oct 27, 2016 · 2 comments · Fixed by #29
Closed

Get rid of Proxy# #27

int-index opened this issue Oct 27, 2016 · 2 comments · Fixed by #29

Comments

@int-index
Copy link
Owner

Can be replaced with TypeApplications and AllowAmbiguousTypes:

{-# LANGUAGE TypeFamilies, RankNTypes, TypeApplications, AllowAmbiguousTypes #-}

class Foo a where
  foo :: forall a' . (a ~ a') => Int

data Bar

instance Foo Bar where
  foo = 42

answer :: Int
answer = foo @Bar
@AaronFriel
Copy link

Since you're using TypeApplications which requires GHC >= 8.0.1, why not go all the way and remove the empty data declarations?

{-# LANGUAGE AllowAmbiguousTypes   #-}
{-# LANGUAGE DataKinds             #-}
{-# LANGUAGE FlexibleInstances     #-}
{-# LANGUAGE TypeApplications      #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE KindSignatures        #-}

import GHC.TypeLits
import Numeric (showIntAtBase)
import Data.Char (intToDigit, chr)

class Foo (a :: Symbol) r where
  foo :: r

instance Foo "Bar" Int where
  foo = 42

instance Foo "Baz" String where
  foo = showIntAtBase 13 intToDigit (6*9) ""

instance Foo "Qux" Char where
  foo = chr (foo @"Bar")

answer :: Int
answer = foo @"Bar"

thisWasntIt :: String
thisWasntIt = foo @"Baz"

orWasAdamsBeingCheeky :: Char
orWasAdamsBeingCheeky = foo @"Qux"

@int-index
Copy link
Owner Author

You can use Symbol-kinded labels since Ether supports poly-kinds. But there's no way I'm declaring this as the official way to use the lib. I have argued against Symbol labels on multiple occasions:

  1. https://www.reddit.com/r/haskell/comments/4ezl8y/monaderror_help/d25g15q/?context=3
  2. OverloadedRecordFields ghc-proposals/ghc-proposals#6 (comment)

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

Successfully merging a pull request may close this issue.

2 participants