Amar Nath Satrawala

Amar Nath Satrawala A N Satrawala

Niner since 2009


  • C9 Lectures: Dr. Erik Meijer - Functional Programming Fundamentals Chapter 10 of 13

    Eric, a very late question


    In object oriented languages, we have the flexibility of defining sub-classes late after super class has been defined. The two definitions need not be done simultaneously. Moreover, there is no limit on the number of sub-classes baring the case of sealed types (which could still be circumvented using containment and defining casts).

    In relation to the analogy of algebraic types and class hierarchies, what is the way in Haskell to extend the types as we can do in object oriented languages.

    For example:

    data Answer = No | Yes

    data AnswerEx = FromAnswer Answer | Unknown


    fromAnswerEx :: AnswerEx -> Answer

    fromAnswerEx FromAnswer a = a

    fromAnswerEx Unknown = No -- in Haskell we have to generate a value of Answer type here


    We could surely define functions for explicit conversion e.g. fromAnswerEx but the compiles can not use them automatically. In code given below we have to use the explicit conversions.


    answers = [Yes, No, fromAnswerEx Unknown, fromAnswerEx FromAnswer Yes]


    The following will not work.


    answers = [Yes, No, Unknown, FromAnswer Yes]


    It is possible there in object oriented languages.


    Is there any pattern/idiom in Haskell to achieve same?


  • Erik Meijer and Matthew Podwysocki - Perspectives on Functional Programming

    I am into moving into functional programming (Haskell, F#) for the last few months. I have read Expert F#, Real World Haskell etc.

    I am liking the ideas and styles and started coding some fun stuff with great things there in F#.

    I was disappointed by the quality (succinctness and clarity) of this video compared to other numerous videos which I have seen from c9 or msdn. (Maybee worst of all which I have seen) Sorry, Matthew and Eric, but I missed the flow and stopped watching the video in the middle.

    I am sorry if I am rude but I got one point from this lecture that intellisence is some kind of bad thing. The examples could have been given either in pseudo code (without any reference to syntax) or with correct syntax of either F# or Haskell.