Created
October 13, 2012 15:36
-
-
Save bblum/3885033 to your computer and use it in GitHub Desktop.
An attempt at translating https://gist.github.com/3885017 to haskell that doesn't compile.
This file contains hidden or 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 MultiParamTypeClasses, FlexibleInstances #-} | |
| module Main where | |
| import Control.Monad (when) | |
| import Control.Applicative ((<$>)) | |
| class Nat n | |
| newtype Zero = Zero () | |
| newtype Suc n = Suc n | |
| instance Nat Zero | |
| instance (Nat n) => Nat (Suc n) | |
| class (Nat n) => List t n v where | |
| each :: (Monad m, List t n v) => (t -> m Bool) -> v -> m () | |
| newtype Nil n = Nil () | |
| newtype (Nat n, List t n v) => Cons t n v = Cons (t, v) | |
| instance List t Zero (Nil Zero) where | |
| each f v = return () | |
| instance (Nat n, List t n v) => List t (Suc n) (Cons t n v) where | |
| each f (Cons(t,v)) = do b <- f t; when b $ each f v | |
| -- This also doesn't compile, even if you change the above into return (). | |
| -- main = each (\x -> do putStrLn $ show x; return True) Cons(1,Cons(2,Cons(3,Nil())))) | |
| main = return () |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
List.hs:26:48:
Ambiguous type variable
n0' in the constraint: (List t n0 v) arising from a use ofeach'Probable fix: add a type signature that fixes these type variable(s)
In the second argument of
($)', namelyeach f v'In the expression: when b $ each f v
In the expression:
do { b <- f t;
when b $ each f v }