def convert_to_basic_types(elem):
    """ Converts an element to primitive types. If the element
    is a list, the inner elements will be converted instead.
    The preference order is bool > int > float > string.

    Parameters
    ----------
    elem : Object
        Element to convert.

    Returns
    -------
    Object
        Primitive object representing the given element.

    """
    if isinstance(elem, int):
        return elem
    if isinstance(elem, float):
        return elem
    if isinstance(elem, bool):
        return elem
    if isinstance(elem, list):
        return [convert_to_basic_types(x) for x in elem]

    elem = str(elem)
    if elem == "True":
        return True
    if elem == "False":
        return False
    
    try:
        result = int(elem)
        return result
    except ValueError:
        try:
            result = float(elem)
            return result
        except ValueError:
            return elem