Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I'm understanding this right, your problem boils down to "I want to stuff things of unknown type into a container, and then at run-time I want to pull them out and run a different function based on their types".</p> <p>There are a couple of possible ways to attack this problem, with varying degrees of complexity.</p> <p>First of all, Haskell has <em>type erasure</em>. When you compile a program, after the compiler checks that all the types are OK, it <em>erases</em> them. So it's impossible, at run-time, to tell what type anything has. This only works because it's impossible, at compile-time, to not know the type of something. This is a verbose way of saying "Haskell is statically-typed".</p> <p>Having just said that, "Haskell with a few extensions" can be made to do this. However, I suspect that your problem may have a much simpler solution...</p> <p>OK, so you want to store different types of stuff. But what do you actually want to <em>do</em> to this stuff once you've stored it? If you just want to execute some function on the data (depending on its type), then why not <em>just store the function itself?</em></p> <p>Think about it. Instead of a container with lots of different types inside it, it would simply contain lots of functions with identical types. You fetch the function you want, and you run it. Done.</p> <p>What's that? You need to be able to run <em>several</em> different functions on your data? Well, in that case, try storing a data structure containing all the functions you need.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload