
a long time since I did some Haskell and my brain has reverted to its OO dogma...
{-# LANGUAGE GADTs, TypeFamilies, TypeOperators, MultiParamTypeClasses, FlexibleInstances, UndecidableInstances, FlexibleContexts #-}
consider
data Next input output where End :: Next () () Next :: (input -> output) -> Next input output
this is a bit like curried function... I can construct
y :: Next Integer (Next String (Next () ())) y = Next (\x -> if (x == 1) then Next (\y -> if (y == "s") then End else End) else Next (\y -> if (y == "t") then End else End))
which is a bit like "Integer->String->()" I can execute it...
exe :: Next input output -> input -> output exe (Next f) i = f i exe End () = ()
p :: Next String (Next () ()) p = exe y 1
ok.... but how do I constrain all the outputs to be of type Next? I don't want this to be valid
z :: Next Integer Integer z = Next (\x -> x + 1)
CONFIDENTIALITY NOTICE This e-mail (and any attached files) is confidential and protected by copyright (and other intellectual property rights). If you are not the intended recipient please e-mail the sender and then delete the email and any attached files immediately. Any further use or dissemination is prohibited. While MTV Networks Europe has taken steps to ensure that this email and any attachments are virus free, it is your responsibility to ensure that this message and any attachments are virus free and do not affect your systems / data. Communicating by email is not 100% secure and carries risks such as delay, data corruption, non-delivery, wrongful interception and unauthorised amendment. If you communicate with us by e-mail, you acknowledge and assume these risks, and you agree to take appropriate measures to minimise these risks when e-mailing us. MTV Networks International, MTV Networks UK & Ireland, Greenhouse, Nickelodeon Viacom Consumer Products, VBSi, Viacom Brand Solutions International, Be Viacom, Viacom International Media Networks and VIMN and Comedy Central are all trading names of MTV Networks Europe. MTV Networks Europe is a partnership between MTV Networks Europe Inc. and Viacom Networks Europe Inc. Address for service in Great Britain is 17-29 Hawley Crescent, London, NW1 8TT.

It’s coming back to me……my OO brain is trying to tell me to constrain the types….
{-# LANGUAGE GADTs, TypeFamilies, TypeOperators, MultiParamTypeClasses, FlexibleInstances, UndecidableInstances, FlexibleContexts #-}
This works
data Next input output where End :: Next () () Next :: (input -> (Next input2 output2)) -> Next input (Next input2 output2)
From: Haskell-Cafe [mailto:haskell-cafe-bounces@haskell.org] On Behalf Of Nicholls, Mark Sent: 10 March 2015 2:54 PM To: Haskell Cafe Subject: [Haskell-cafe] Basic question about recursive data type... a long time since I did some Haskell and my brain has reverted to its OO dogma...
{-# LANGUAGE GADTs, TypeFamilies, TypeOperators, MultiParamTypeClasses, FlexibleInstances, UndecidableInstances, FlexibleContexts #-}
consider
data Next input output where End :: Next () () Next :: (input -> output) -> Next input output
this is a bit like curried function... I can construct
y :: Next Integer (Next String (Next () ())) y = Next (\x -> if (x == 1) then Next (\y -> if (y == "s") then End else End) else Next (\y -> if (y == "t") then End else End))
which is a bit like "Integer->String->()" I can execute it...
exe :: Next input output -> input -> output exe (Next f) i = f i exe End () = ()
p :: Next String (Next () ()) p = exe y 1
ok.... but how do I constrain all the outputs to be of type Next? I don't want this to be valid
z :: Next Integer Integer z = Next (\x -> x + 1)
CONFIDENTIALITY NOTICE This e-mail (and any attached files) is confidential and protected by copyright (and other intellectual property rights). If you are not the intended recipient please e-mail the sender and then delete the email and any attached files immediately. Any further use or dissemination is prohibited. While MTV Networks Europe has taken steps to ensure that this email and any attachments are virus free, it is your responsibility to ensure that this message and any attachments are virus free and do not affect your systems / data. Communicating by email is not 100% secure and carries risks such as delay, data corruption, non-delivery, wrongful interception and unauthorised amendment. If you communicate with us by e-mail, you acknowledge and assume these risks, and you agree to take appropriate measures to minimise these risks when e-mailing us. MTV Networks International, MTV Networks UK & Ireland, Greenhouse, Nickelodeon Viacom Consumer Products, VBSi, Viacom Brand Solutions International, Be Viacom, Viacom International Media Networks and VIMN and Comedy Central are all trading names of MTV Networks Europe. MTV Networks Europe is a partnership between MTV Networks Europe Inc. and Viacom Networks Europe Inc. Address for service in Great Britain is 17-29 Hawley Crescent, London, NW1 8TT. CONFIDENTIALITY NOTICE This e-mail (and any attached files) is confidential and protected by copyright (and other intellectual property rights). If you are not the intended recipient please e-mail the sender and then delete the email and any attached files immediately. Any further use or dissemination is prohibited. While MTV Networks Europe has taken steps to ensure that this email and any attachments are virus free, it is your responsibility to ensure that this message and any attachments are virus free and do not affect your systems / data. Communicating by email is not 100% secure and carries risks such as delay, data corruption, non-delivery, wrongful interception and unauthorised amendment. If you communicate with us by e-mail, you acknowledge and assume these risks, and you agree to take appropriate measures to minimise these risks when e-mailing us. MTV Networks International, MTV Networks UK & Ireland, Greenhouse, Nickelodeon Viacom Consumer Products, VBSi, Viacom Brand Solutions International, Be Viacom, Viacom International Media Networks and VIMN and Comedy Central are all trading names of MTV Networks Europe. MTV Networks Europe is a partnership between MTV Networks Europe Inc. and Viacom Networks Europe Inc. Address for service in Great Britain is 17-29 Hawley Crescent, London, NW1 8TT.
participants (1)
-
Nicholls, Mark