Created
January 12, 2014 15:25
-
-
Save hugoduncan/8385991 to your computer and use it in GitHub Desktop.
An attempt to create a function that process an external representation of different data types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE ScopedTypeVariables #-} | |
module Test () where | |
-- a type class to specify parsing and encoding of a type | |
-- (in reality I'm using hedn, which is similar to aeson) | |
class T a where | |
f :: String -> a | |
g :: a -> String | |
-- I want a function that can take a string, parse it, do something | |
-- on the resulting instance, and then encode it back into a string. | |
-- To do this I'm trying to use a dummy initial argument that is used | |
-- to specify the type the String is supposed to be parsed to. | |
invf :: (T a) => a -> String -> String | |
invf x y = g (f y :: a) | |
-- Test.hs:17:12: | |
-- Could not deduce (T a0) arising from a use of `g' | |
-- from the context (T a) | |
-- bound by the type signature for | |
-- invf :: T a => a -> String -> String | |
-- at Pallet/Test.hs:16:9-38 | |
-- The type variable `a0' is ambiguous | |
-- Possible fix: add a type signature that fixes these type variable(s) | |
-- In the expression: g (f y :: a) | |
-- In an equation for `invf': invf x y = g (f y :: a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Moving invf to be a function in the type class T seems to work.