Get a newtype'd records underlying type in purescript
up vote
0
down vote
favorite
I'm trying to see if there's an easy way to get the type of a newtype'd record to put in function signatures.
newtype T1 = T1 foo:: Int
derive instance newtypeT1 :: Newtype T1 _
... other classes that require me to newtype the record ...
I know I can access a records members with _.property and I can compose that with unwrapunwrap >>> _.property to get a function for that property, but I'd like to write a function similar to
testFoo :: forall a. (_ -> a) -> Effect a
testFoo accessor = (unwrap >>> accessor) <$> loadT1
This works but the wildcard symbol gives an warning, but I'm not sure how to get that record definition from T1. (This is a minimal example, I have a massive property object that is from an external source.
A workaround I've been using for now has been to declare my type like
type InnerT1 = foo ::Int
newtype T1 = T1 InnerT1
and exporting that InnerT1 so it can be used in my test file, but this seems a bit clunky and I am wondering if there is a better way?
purescript
add a comment |
up vote
0
down vote
favorite
I'm trying to see if there's an easy way to get the type of a newtype'd record to put in function signatures.
newtype T1 = T1 foo:: Int
derive instance newtypeT1 :: Newtype T1 _
... other classes that require me to newtype the record ...
I know I can access a records members with _.property and I can compose that with unwrapunwrap >>> _.property to get a function for that property, but I'd like to write a function similar to
testFoo :: forall a. (_ -> a) -> Effect a
testFoo accessor = (unwrap >>> accessor) <$> loadT1
This works but the wildcard symbol gives an warning, but I'm not sure how to get that record definition from T1. (This is a minimal example, I have a massive property object that is from an external source.
A workaround I've been using for now has been to declare my type like
type InnerT1 = foo ::Int
newtype T1 = T1 InnerT1
and exporting that InnerT1 so it can be used in my test file, but this seems a bit clunky and I am wondering if there is a better way?
purescript
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to see if there's an easy way to get the type of a newtype'd record to put in function signatures.
newtype T1 = T1 foo:: Int
derive instance newtypeT1 :: Newtype T1 _
... other classes that require me to newtype the record ...
I know I can access a records members with _.property and I can compose that with unwrapunwrap >>> _.property to get a function for that property, but I'd like to write a function similar to
testFoo :: forall a. (_ -> a) -> Effect a
testFoo accessor = (unwrap >>> accessor) <$> loadT1
This works but the wildcard symbol gives an warning, but I'm not sure how to get that record definition from T1. (This is a minimal example, I have a massive property object that is from an external source.
A workaround I've been using for now has been to declare my type like
type InnerT1 = foo ::Int
newtype T1 = T1 InnerT1
and exporting that InnerT1 so it can be used in my test file, but this seems a bit clunky and I am wondering if there is a better way?
purescript
I'm trying to see if there's an easy way to get the type of a newtype'd record to put in function signatures.
newtype T1 = T1 foo:: Int
derive instance newtypeT1 :: Newtype T1 _
... other classes that require me to newtype the record ...
I know I can access a records members with _.property and I can compose that with unwrapunwrap >>> _.property to get a function for that property, but I'd like to write a function similar to
testFoo :: forall a. (_ -> a) -> Effect a
testFoo accessor = (unwrap >>> accessor) <$> loadT1
This works but the wildcard symbol gives an warning, but I'm not sure how to get that record definition from T1. (This is a minimal example, I have a massive property object that is from an external source.
A workaround I've been using for now has been to declare my type like
type InnerT1 = foo ::Int
newtype T1 = T1 InnerT1
and exporting that InnerT1 so it can be used in my test file, but this seems a bit clunky and I am wondering if there is a better way?
purescript
purescript
asked 14 hours ago
Beau Trepp
83821124
83821124
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
You can use the Newtype class to get at the inner type:
testFoo :: forall a inner. Newtype T1 inner => (inner -> a) -> Effect a
testFoo accessor = (unwrap >>> accessor) <$> loadT1
This works without additional annotations, because the class has a functional dependency Newtype a b | a -> b, which means that the inner type is uniquely determined by the outer type.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You can use the Newtype class to get at the inner type:
testFoo :: forall a inner. Newtype T1 inner => (inner -> a) -> Effect a
testFoo accessor = (unwrap >>> accessor) <$> loadT1
This works without additional annotations, because the class has a functional dependency Newtype a b | a -> b, which means that the inner type is uniquely determined by the outer type.
add a comment |
up vote
0
down vote
You can use the Newtype class to get at the inner type:
testFoo :: forall a inner. Newtype T1 inner => (inner -> a) -> Effect a
testFoo accessor = (unwrap >>> accessor) <$> loadT1
This works without additional annotations, because the class has a functional dependency Newtype a b | a -> b, which means that the inner type is uniquely determined by the outer type.
add a comment |
up vote
0
down vote
up vote
0
down vote
You can use the Newtype class to get at the inner type:
testFoo :: forall a inner. Newtype T1 inner => (inner -> a) -> Effect a
testFoo accessor = (unwrap >>> accessor) <$> loadT1
This works without additional annotations, because the class has a functional dependency Newtype a b | a -> b, which means that the inner type is uniquely determined by the outer type.
You can use the Newtype class to get at the inner type:
testFoo :: forall a inner. Newtype T1 inner => (inner -> a) -> Effect a
testFoo accessor = (unwrap >>> accessor) <$> loadT1
This works without additional annotations, because the class has a functional dependency Newtype a b | a -> b, which means that the inner type is uniquely determined by the outer type.
answered 7 hours ago
Fyodor Soikin
41.1k56295
41.1k56295
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53236838%2fget-a-newtyped-records-underlying-type-in-purescript%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password