Haskell dynamic binding

I am looking for a way to dynamically bind.

Circuit:

It allows you to have an application with many data filters that have all the same contours (function names, internal data types, some exported data types of the same class).

It would be great to check the current .so files, load only those that are needed based on command line arguments and then start. I do not want to change or recompile the application every time a new module is added.

Is something like that possible today?

I tried to hack with the help System.Plugins, failed every time. Sometimes I hate strong type checking.

EDIT

If I wrote something like this directly and gave it the type of hint when calling makeChunks, this is normal, otherwise nothing

--SharedClass --should create common interface
class (Eq c, Show c) => Chunks c where
    makeChunks :: String -> [c]

--Plugin --one concrete implementation
import SharedClass
data MyChunk = SmallChunk Char deriving (Eq) 
instance Chunks MyChunk where
    makeChunks _ = [SmallChunk 's']
instance Show MyChunk where
    show (SmallChunk s) = [s]

--main
import SharedClass
    --load plugin somehow
print $ makeChunks "abcd"
+4

Source: https://habr.com/ru/post/1524142/


All Articles