<commit_before>from ctypes import *
import os.path
import subprocess

# Load libhapy
hapy = cdll.LoadLibrary("./libhapy.so")

# Set libhapy typeinfo
hapy.retrieveInt.restype = c_int
hapy.retrieveBool.restype = lambda i: False if i is 0 else True #TODO: not working, must debug
hapy.retrieveDouble.restype = c_double
hapy.retrieveString.restype = c_char_p

class HaskellType:
    def __init__(self, name, cls, applyFun, retrieveFun):
        self.name = name
        self.cls = cls
        self.applyFun = applyFun
        self.retrieveFun = retrieveFun

    def __repr__(self):
        return self.__class__.__name__ + "(" + self.name + ")"

_types = [ HaskellType("Int"    , int   , hapy.applyInt    , hapy.retrieveInt)
         , HaskellType("Bool"   , bool  , hapy.applyBool   , hapy.retrieveBool)
         , HaskellType("Double" , float , hapy.applyDouble , hapy.retrieveDouble)
         , HaskellType("String" , str   , hapy.applyString , hapy.retrieveString)
         ]
_KNOWN_TYPES = { type.name:type for type in _types }

def _isGeneric(type):
    return type[0].islower()

def _knownTypeFromClass(cls):
    for type in _KNOWN_TYPES.values():
        if type.cls == cls:
            return type
    return None
                
class HaskellFunctionType:
    def __init__(self, name, argTypes, returnType):
        self.name = name
        self.argTypes = argTypes
        self.returnType = returnType

    def __repr__(self):
        return self.__class__.__name__ + "(" + repr(self.name) + ", " + repr(self.argTypes) + ", " + repr(self.returnType) + ")"

    @staticmethod
    def parse(s):
        [name, rest] = s.split("::")
        name = name.strip()
        types = rest.split("->")
        types = map(str.strip, types)
        return HaskellFunctionType(name, types[:-1], types[-1])


class HaskellObject:
    def __init__(self, objPtr, name, argTypes, returnType):
        self.ptr = objPtr
        self.name = name
        self.argTypes = argTypes
        self.returnType = returnType

    def __repr__(self):
        return self.__class__.__name__ + "(" + repr(self.name) + ", " + repr(self.argTypes) + ", " + repr(self.returnType) + ")"

    def isFullyApplied(self):
        return self.argTypes == []

    def __call__(self, arg, *args, **kwargs):
        typecheck = kwargs.get("typecheck", False)

        # make sure object is still valid
        if self.ptr is None:
            raise RuntimeError("Value already retrieved: object no longer callable")

        if self.isFullyApplied():
            return RuntimeError("Too many arguments")

        # adjust generic type if it exists<commit_msg>Removed dead code<commit_after>from ctypes import *
import os.path
import subprocess

# Load libhapy
hapy = cdll.LoadLibrary("./libhapy.so")

# Set libhapy typeinfo
hapy.retrieveInt.restype = c_int
hapy.retrieveBool.restype = lambda i: False if i is 0 else True #TODO: not working, must debug
hapy.retrieveDouble.restype = c_double
hapy.retrieveString.restype = c_char_p

class HaskellType:
    def __init__(self, name, cls, applyFun, retrieveFun):
        self.name = name
        self.cls = cls
        self.applyFun = applyFun
        self.retrieveFun = retrieveFun

    def __repr__(self):
        return self.__class__.__name__ + "(" + self.name + ")"

_types = [ HaskellType("Int"    , int   , hapy.applyInt    , hapy.retrieveInt)
         , HaskellType("Bool"   , bool  , hapy.applyBool   , hapy.retrieveBool)
         , HaskellType("Double" , float , hapy.applyDouble , hapy.retrieveDouble)
         , HaskellType("String" , str   , hapy.applyString , hapy.retrieveString)
         ]
_KNOWN_TYPES = { type.name:type for type in _types }

def _isGeneric(type):
    return type[0].islower()

def _knownTypeFromClass(cls):
    for type in _KNOWN_TYPES.values():
        if type.cls == cls:
            return type
    return None


class HaskellObject:
    def __init__(self, objPtr, name, argTypes, returnType):
        self.ptr = objPtr
        self.name = name
        self.argTypes = argTypes
        self.returnType = returnType

    def __repr__(self):
        return self.__class__.__name__ + "(" + repr(self.name) + ", " + repr(self.argTypes) + ", " + repr(self.returnType) + ")"

    def isFullyApplied(self):
        return self.argTypes == []

    def __call__(self, arg, *args, **kwargs):
        typecheck = kwargs.get("typecheck", False)

        # make sure object is still valid
        if self.ptr is None:
            raise RuntimeError("Value already retrieved: object no longer callable")

        if self.isFullyApplied():
            return RuntimeError("Too many arguments")

        # adjust generic type if it exists
{'fraction_non_alphanumeric': 0.11284796573875804, 'fraction_numerical': 0.001284796573875803, 'mean_word_length': 2.7012678288431062, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6102706', 'n_tokens_mistral': 1502, 'n_tokens_neox': 1462, 'n_words': 360}