Re: [Haskell-cafe] Re: Functional version of this OO snippet

2008-12-05 Thread ajb
G'day all. Thomas Davie wrote: class IEngine a where foo :: a -> String bar :: a -> String -> String "Apfelmus, Heinrich" <[EMAIL PROTECTED]> replied: You don't even need a type class, a simple data type is enough. data Engine = Engine { foo :: IO (), bar :: String -> IO () } There

Re: [Haskell-cafe] Re: Functional version of this OO snippet

2008-12-05 Thread Jonathan Cast
On Fri, 2008-12-05 at 18:50 +0100, Thomas Davie wrote: > On 5 Dec 2008, at 17:46, Duncan Coutts wrote: > > > On Fri, 2008-12-05 at 17:06 +0100, Thomas Davie wrote: > >> On 5 Dec 2008, at 17:00, Duncan Coutts wrote: > >> > >>> On Fri, 2008-12-05 at 16:50 +0100, Thomas Davie wrote: > >>> > Sure

Re: [Haskell-cafe] Re: Functional version of this OO snippet

2008-12-05 Thread Thomas Davie
On 5 Dec 2008, at 17:46, Duncan Coutts wrote: On Fri, 2008-12-05 at 17:06 +0100, Thomas Davie wrote: On 5 Dec 2008, at 17:00, Duncan Coutts wrote: On Fri, 2008-12-05 at 16:50 +0100, Thomas Davie wrote: Sure, and he could then use a fold instead of a map. Reading files is problematic, but

Re: [Haskell-cafe] Re: Functional version of this OO snippet

2008-12-05 Thread Duncan Coutts
On Fri, 2008-12-05 at 17:06 +0100, Thomas Davie wrote: > On 5 Dec 2008, at 17:00, Duncan Coutts wrote: > > > On Fri, 2008-12-05 at 16:50 +0100, Thomas Davie wrote: > > > >> Sure, and he could then use a fold instead of a map. Reading files > >> is > >> problematic, but as long as you're only do

Re: [Haskell-cafe] Re: Functional version of this OO snippet

2008-12-05 Thread Thomas Davie
On 5 Dec 2008, at 17:00, Duncan Coutts wrote: On Fri, 2008-12-05 at 16:50 +0100, Thomas Davie wrote: Sure, and he could then use a fold instead of a map. Reading files is problematic, but as long as you're only doing it once (the most common situation) is entirely fine wrapped up in an u

Re: [Haskell-cafe] Re: Functional version of this OO snippet

2008-12-05 Thread Duncan Coutts
On Fri, 2008-12-05 at 16:50 +0100, Thomas Davie wrote: > Sure, and he could then use a fold instead of a map. Reading files is > problematic, but as long as you're only doing it once (the most common > situation) is entirely fine wrapped up in an unsafePerformIO. No! Please don't go tel

Re: [Haskell-cafe] Re: Functional version of this OO snippet

2008-12-05 Thread Thomas Davie
On 5 Dec 2008, at 16:42, Apfelmus, Heinrich wrote: Thomas Davie wrote: You don't even need a type class, a simple data type is enough. Very true, but I disagree that you've made it functional in any way, IO is all about sequencing things, it's very much not a functional style data Engin

[Haskell-cafe] Re: Functional version of this OO snippet

2008-12-05 Thread Apfelmus, Heinrich
Thomas Davie wrote: >> You don't even need a type class, a simple data type is enough. > > Very true, but I disagree that you've made it functional in any way, IO > is all about sequencing things, it's very much not a functional style >> >> data Engine = Engine { foo :: IO (), bar :: String -> IO

Re: [Haskell-cafe] Re: Functional version of this OO snippet

2008-12-05 Thread Thomas Davie
You don't even need a type class, a simple data type is enough. Very true, but I disagree that you've made it functional in any way, IO is all about sequencing things, it's very much not a functional style data Engine = Engine { foo :: IO (), bar :: String -> IO () } run e = processComman

[Haskell-cafe] Re: Functional version of this OO snippet

2008-12-05 Thread Apfelmus, Heinrich
Thomas Davie wrote: > Andrew Wagner wrote: > >> Hi all, >> public interface IEngine { >> void foo(); >> void bar(string bah); >> ... >> } >> public class Program { >> public void Run(IEngine engine){ >> while(true){ >>string command = GetLine(); >>if (command.startsWith("foo")){ >>